|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xoops\Core\Kernel\Handlers; |
|
13
|
|
|
|
|
14
|
|
|
use Xoops\Core\Database\Connection; |
|
15
|
|
|
use Xoops\Core\Kernel\CriteriaElement; |
|
16
|
|
|
use Xoops\Core\Kernel\XoopsPersistableObjectHandler; |
|
17
|
|
|
use Doctrine\DBAL\FetchMode; |
|
18
|
|
|
use Doctrine\DBAL\ParameterType; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* XoopsBlockHandler |
|
22
|
|
|
* |
|
23
|
|
|
* @category Xoops\Core\Kernel\Handlers\XoopsBlockHandler |
|
24
|
|
|
* @package Xoops\Core\Kernel |
|
25
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
|
26
|
|
|
* @author Gregory Mage (AKA Mage) |
|
27
|
|
|
* @author trabis <[email protected]> |
|
28
|
|
|
* @copyright 2000-2019 XOOPS Project (https://xoops.org) |
|
29
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
30
|
|
|
*/ |
|
31
|
|
|
class XoopsBlockHandler extends XoopsPersistableObjectHandler |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Constructor |
|
35
|
|
|
* |
|
36
|
|
|
* @param Connection|null $db database |
|
37
|
|
|
*/ |
|
38
|
20 |
|
public function __construct(Connection $db = null) |
|
39
|
|
|
{ |
|
40
|
20 |
|
parent::__construct($db, 'system_block', '\Xoops\Core\Kernel\Handlers\XoopsBlock', 'bid', 'name'); |
|
41
|
20 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Insert a block |
|
45
|
|
|
* |
|
46
|
|
|
* @param XoopsBlock $obj block object to persist |
|
47
|
|
|
* @param bool $force force insert even in 'safe' requests |
|
48
|
|
|
* |
|
49
|
|
|
* @return int|false id of insert, or false on error |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function insertBlock(XoopsBlock $obj, $force = false) |
|
52
|
|
|
{ |
|
53
|
1 |
|
$obj->setVar('last_modified', time()); |
|
54
|
1 |
|
return parent::insert($obj, $force); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Delete a ID from the database |
|
59
|
|
|
* |
|
60
|
|
|
* @param XoopsBlock $obj object to delete |
|
61
|
|
|
* |
|
62
|
|
|
* @return bool |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function deleteBlock(XoopsBlock $obj) |
|
65
|
|
|
{ |
|
66
|
1 |
|
if (!parent::delete($obj)) { |
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
70
|
1 |
|
$eb = $qb->expr(); |
|
71
|
1 |
|
$qb ->deletePrefix('system_permission', null) |
|
72
|
1 |
|
->where($eb->eq('gperm_name', $eb->literal('block_read'))) |
|
73
|
1 |
|
->andWhere($eb->eq('gperm_itemid', $qb->createNamedParameter($obj->getVar('bid'), ParameterType::INTEGER))) |
|
74
|
1 |
|
->andWhere($eb->eq('gperm_modid', $qb->createNamedParameter(1, ParameterType::INTEGER))) |
|
75
|
1 |
|
->execute(); |
|
76
|
|
|
|
|
77
|
1 |
|
$qb ->deletePrefix('system_blockmodule', null) |
|
78
|
1 |
|
->where($eb->eq('block_id', $qb->createNamedParameter($obj->getVar('bid'), ParameterType::INTEGER))) |
|
79
|
1 |
|
->execute(); |
|
80
|
|
|
|
|
81
|
1 |
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* retrieve array of XoopsBlock objects meeting certain conditions |
|
86
|
|
|
* |
|
87
|
|
|
* @param CriteriaElement|null $criteria criteria to match |
|
88
|
|
|
* @param bool $id_as_key should the blocks' bid be the key for the returned array? |
|
89
|
|
|
* |
|
90
|
|
|
* @return XoopsBlock[] |
|
91
|
|
|
**/ |
|
92
|
2 |
|
public function getDistinctObjects(CriteriaElement $criteria = null, $id_as_key = false) |
|
93
|
|
|
{ |
|
94
|
2 |
|
$ret = array(); |
|
95
|
|
|
|
|
96
|
2 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
97
|
2 |
|
$eb = $qb->expr(); |
|
98
|
2 |
|
$qb ->select('DISTINCT(b.bid)') |
|
99
|
2 |
|
->addSelect('b.*') |
|
100
|
2 |
|
->fromPrefix('system_block', 'b') |
|
101
|
2 |
|
->leftJoinPrefix('b', 'system_blockmodule', 'l', $eb->eq('b.bid', 'l.block_id')); |
|
102
|
|
|
|
|
103
|
2 |
|
if (isset($criteria) && ($criteria instanceof CriteriaElement)) { |
|
104
|
1 |
|
$criteria->renderQb($qb); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
2 |
|
$result = $qb->execute(); |
|
108
|
2 |
|
if (!$result) { |
|
109
|
|
|
return $ret; |
|
110
|
|
|
} |
|
111
|
2 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
112
|
1 |
|
$block = new XoopsBlock(); |
|
113
|
1 |
|
$block->assignVars($myrow); |
|
114
|
1 |
|
if (!$id_as_key) { |
|
115
|
1 |
|
$ret[] = $block; |
|
116
|
|
|
} else { |
|
117
|
|
|
$ret[$myrow['bid']] = $block; |
|
118
|
|
|
} |
|
119
|
1 |
|
unset($block); |
|
120
|
|
|
} |
|
121
|
2 |
|
return $ret; |
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* get a list of blocks matching certain conditions |
|
127
|
|
|
* |
|
128
|
|
|
* @param CriteriaElement|null $criteria conditions to match |
|
129
|
|
|
* |
|
130
|
|
|
* @return array array of blocks matching the conditions |
|
131
|
|
|
**/ |
|
132
|
1 |
|
public function getNameList(CriteriaElement $criteria = null) |
|
133
|
|
|
{ |
|
134
|
1 |
|
$blocks = $this->getObjects($criteria, true); |
|
135
|
1 |
|
$ret = array(); |
|
136
|
1 |
|
foreach (array_keys($blocks) as $i) { |
|
137
|
1 |
|
$name = (!$blocks[$i]->isCustom()) ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title'); |
|
138
|
1 |
|
$ret[$i] = $name; |
|
139
|
|
|
} |
|
140
|
1 |
|
return $ret; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* get all the blocks that match the supplied parameters |
|
145
|
|
|
* |
|
146
|
|
|
* @param int|int[] $groupid groupid (can be an array) |
|
147
|
|
|
* @param bool $asobject retrieve as objects |
|
148
|
|
|
* @param int $side values: |
|
149
|
|
|
* 0: sideblock - left |
|
150
|
|
|
* 1: sideblock - right |
|
151
|
|
|
* 2: sideblock - left and right |
|
152
|
|
|
* 3: centerblock - left |
|
153
|
|
|
* 4: centerblock - right |
|
154
|
|
|
* 5: centerblock - center |
|
155
|
|
|
* 6: centerblock - left, right, center |
|
156
|
|
|
* @param int|null $visible 0: not visible 1: visible |
|
157
|
|
|
* @param string $orderby order of the blocks |
|
158
|
|
|
* @param int $isactive 1: active or 0:inactive blocks |
|
159
|
|
|
* |
|
160
|
|
|
* @return array of block objects |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public function getAllBlocksByGroup( |
|
163
|
|
|
$groupid, |
|
164
|
|
|
$asobject = true, |
|
165
|
|
|
$side = null, |
|
166
|
|
|
$visible = null, |
|
167
|
|
|
$orderby = "b.weight,b.bid", |
|
168
|
|
|
$isactive = 1 |
|
169
|
|
|
) { |
|
170
|
1 |
|
$ret = array(); |
|
171
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
172
|
1 |
|
$eb = $qb->expr(); |
|
173
|
1 |
|
if ($asobject) { |
|
174
|
1 |
|
$qb ->select('b.*'); |
|
175
|
|
|
} else { |
|
176
|
1 |
|
$qb ->select('b.bid'); |
|
177
|
|
|
} |
|
178
|
1 |
|
$qb ->fromPrefix('system_block', 'b') |
|
179
|
1 |
|
->leftJoinPrefix('b', 'system_permission', 'l', $eb->eq('b.bid', 'l.gperm_itemid')) |
|
180
|
1 |
|
->where($eb->eq('gperm_name', $eb->literal('block_read'))) |
|
181
|
1 |
|
->andWhere($eb->eq('gperm_modid', 1)); |
|
182
|
|
|
|
|
183
|
1 |
|
if (is_array($groupid)) { |
|
184
|
1 |
|
if (count($groupid) > 1) { |
|
185
|
1 |
|
$in=array(); |
|
186
|
1 |
|
foreach ($groupid as $gid) { |
|
187
|
1 |
|
$in[] = $qb->createNamedParameter($gid, ParameterType::INTEGER); |
|
188
|
|
|
} |
|
189
|
1 |
|
$qb->andWhere($eb->in('l.gperm_groupid', $in)); |
|
190
|
|
|
} |
|
191
|
|
|
} else { |
|
192
|
1 |
|
$qb->andWhere($eb->eq('l.gperm_groupid', $qb->createNamedParameter($groupid, ParameterType::INTEGER))); |
|
193
|
|
|
} |
|
194
|
1 |
|
$qb->andWhere($eb->eq('b.isactive', $qb->createNamedParameter($isactive, ParameterType::INTEGER))); |
|
195
|
1 |
|
if (isset($side)) { |
|
196
|
|
|
// get both sides in sidebox? (some themes need this) |
|
197
|
1 |
|
if ($side == XOOPS_SIDEBLOCK_BOTH) { |
|
198
|
1 |
|
$qb->andWhere($eb->in('b.side', array(0,1))); |
|
199
|
1 |
|
} elseif ($side == XOOPS_CENTERBLOCK_ALL) { |
|
200
|
1 |
|
$qb->andWhere($eb->in('b.side', array(3,4,5,7,8,9))); |
|
201
|
|
|
} else { |
|
202
|
1 |
|
$qb->andWhere($eb->eq('b.side', $qb->createNamedParameter($side, ParameterType::INTEGER))); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
1 |
|
if (isset($visible)) { |
|
206
|
1 |
|
$qb->andWhere($eb->eq('b.visible', $qb->createNamedParameter($visible, ParameterType::INTEGER))); |
|
207
|
|
|
} |
|
208
|
1 |
|
$qb->orderBy($orderby); |
|
209
|
1 |
|
$result = $qb->execute(); |
|
210
|
1 |
|
$added = array(); |
|
211
|
1 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
212
|
1 |
|
if (!in_array($myrow['bid'], $added)) { |
|
213
|
1 |
|
if (!$asobject) { |
|
214
|
1 |
|
$ret[] = $myrow['bid']; |
|
215
|
|
|
} else { |
|
216
|
1 |
|
$ret[] = new XoopsBlock($myrow); |
|
217
|
|
|
} |
|
218
|
1 |
|
array_push($added, $myrow['bid']); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
1 |
|
return $ret; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* getAllBlocks matching selection criteria |
|
226
|
|
|
* |
|
227
|
|
|
* @param string $rettype what to return, values can be object, list or id |
|
228
|
|
|
* @param int $side block location (side) |
|
229
|
|
|
* @param int|null $visible null for all, 0 not visible, 1 for visible only |
|
230
|
|
|
* @param string $orderby comma separated columns to order by |
|
231
|
|
|
* @param int $isactive 1: active or 0:inactive blocks |
|
232
|
|
|
* |
|
233
|
|
|
* @return array |
|
234
|
|
|
*/ |
|
235
|
1 |
|
public function getAllBlocks( |
|
236
|
|
|
$rettype = "object", |
|
237
|
|
|
$side = null, |
|
238
|
|
|
$visible = null, |
|
239
|
|
|
$orderby = "side,weight,bid", |
|
240
|
|
|
$isactive = 1 |
|
241
|
|
|
) { |
|
242
|
1 |
|
$ret = array(); |
|
243
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
244
|
1 |
|
$eb = $qb->expr(); |
|
245
|
|
|
|
|
246
|
1 |
|
$qb ->fromPrefix('system_block', null) |
|
247
|
1 |
|
->where($eb->eq('isactive', $qb->createNamedParameter($isactive, ParameterType::INTEGER))); |
|
248
|
1 |
|
if (isset($side)) { |
|
249
|
|
|
// get both sides in sidebox? (some themes need this) |
|
250
|
1 |
|
if ($side == XOOPS_SIDEBLOCK_BOTH) { |
|
251
|
1 |
|
$qb->andWhere($eb->in('side', array(0,1))); |
|
252
|
|
|
} elseif ($side == XOOPS_CENTERBLOCK_ALL) { |
|
253
|
|
|
$qb->andWhere($eb->in('side', array(3,4,5,7,8,9))); |
|
254
|
|
|
} else { |
|
255
|
|
|
$qb->andWhere($eb->eq('side', $qb->createNamedParameter($side, ParameterType::INTEGER))); |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
1 |
|
if (isset($visible)) { |
|
259
|
1 |
|
$qb->andWhere($eb->eq('visible', $qb->createNamedParameter($visible, ParameterType::INTEGER))); |
|
260
|
|
|
} |
|
261
|
1 |
|
$qb->orderBy($orderby); |
|
262
|
|
|
switch ($rettype) { |
|
263
|
1 |
|
case "object": |
|
264
|
1 |
|
$qb->select('*'); |
|
265
|
1 |
|
$result = $qb->execute(); |
|
266
|
1 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
267
|
1 |
|
$ret[] = new XoopsBlock($myrow); |
|
268
|
|
|
} |
|
269
|
1 |
|
break; |
|
270
|
1 |
|
case "list": |
|
271
|
1 |
|
$qb->select('*'); |
|
272
|
1 |
|
$result = $qb->execute(); |
|
273
|
1 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
274
|
1 |
|
$block = new XoopsBlock($myrow); |
|
275
|
1 |
|
$title = $block->getVar("title"); |
|
276
|
1 |
|
$title = empty($title) ? $block->getVar("name") : $title; |
|
277
|
1 |
|
$ret[$block->getVar("bid")] = $title; |
|
278
|
|
|
} |
|
279
|
1 |
|
break; |
|
280
|
1 |
|
case "id": |
|
281
|
1 |
|
$qb->select('bid'); |
|
282
|
1 |
|
$result = $qb->execute(); |
|
283
|
1 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
284
|
1 |
|
$ret[] = $myrow['bid']; |
|
285
|
|
|
} |
|
286
|
1 |
|
break; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
1 |
|
return $ret; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* get blocks by module id |
|
294
|
|
|
* |
|
295
|
|
|
* @param int $moduleid module id |
|
296
|
|
|
* @param bool $asobject true to fetch as objects, otherwise associative array |
|
297
|
|
|
* |
|
298
|
|
|
* @return array of block information |
|
299
|
|
|
*/ |
|
300
|
1 |
|
public function getByModule($moduleid, $asobject = true) |
|
301
|
|
|
{ |
|
302
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
303
|
1 |
|
$eb = $qb->expr(); |
|
304
|
|
|
|
|
305
|
1 |
|
$qb ->fromPrefix('system_block', null) |
|
306
|
1 |
|
->where($eb->eq('mid', $qb->createNamedParameter($moduleid, ParameterType::INTEGER))); |
|
307
|
1 |
|
if ($asobject == true) { |
|
|
|
|
|
|
308
|
1 |
|
$qb->select('*'); |
|
309
|
|
|
} else { |
|
310
|
1 |
|
$qb->select('bid'); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
1 |
|
$ret = array(); |
|
314
|
1 |
|
$result = $qb->execute(); |
|
315
|
1 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
316
|
|
|
if ($asobject) { |
|
317
|
|
|
$ret[] = new XoopsBlock($myrow); |
|
318
|
|
|
} else { |
|
319
|
|
|
$ret[] = $myrow['bid']; |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
1 |
|
return $ret; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* XoopsBlock::getAllByGroupModule() |
|
327
|
|
|
* |
|
328
|
|
|
* @param mixed $groupid int group id, int[] of group ids, |
|
329
|
|
|
* @param integer $module_id module id |
|
330
|
|
|
* @param boolean $toponlyblock only for top block |
|
331
|
|
|
* @param mixed $visible restrict by visible values |
|
332
|
|
|
* @param string $orderby comma separated list of columns to order by |
|
333
|
|
|
* @param integer $isactive restrict by isactive values |
|
334
|
|
|
* |
|
335
|
|
|
* @return array |
|
336
|
|
|
*/ |
|
337
|
3 |
|
public function getAllByGroupModule( |
|
338
|
|
|
$groupid, |
|
339
|
|
|
$module_id = 0, |
|
340
|
|
|
$toponlyblock = false, |
|
341
|
|
|
$visible = null, |
|
342
|
|
|
$orderby = 'b.weight, m.block_id', |
|
343
|
|
|
$isactive = 1 |
|
344
|
|
|
) { |
|
345
|
3 |
|
$ret = array(); |
|
346
|
|
|
|
|
347
|
3 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
348
|
3 |
|
$eb = $qb->expr(); |
|
349
|
|
|
|
|
350
|
3 |
|
$blockids=null; |
|
351
|
3 |
|
if (isset($groupid)) { |
|
352
|
3 |
|
$qb ->select('DISTINCT gperm_itemid') |
|
353
|
3 |
|
->fromPrefix('system_permission', null) |
|
354
|
3 |
|
->where($eb->eq('gperm_name', $eb->literal('block_read'))) |
|
355
|
3 |
|
->andWhere('gperm_modid=1'); |
|
356
|
|
|
|
|
357
|
3 |
|
if (is_array($groupid) && !empty($groupid)) { |
|
358
|
3 |
|
$qb->andWhere($eb->in('gperm_groupid', $groupid)); |
|
359
|
|
|
} else { |
|
360
|
1 |
|
if ((int)($groupid) > 0) { |
|
361
|
1 |
|
$qb->andWhere($eb->eq('gperm_groupid', $groupid)); |
|
362
|
|
|
} |
|
363
|
|
|
} |
|
364
|
3 |
|
$result = $qb->execute(); |
|
365
|
3 |
|
$blockids = $result->fetchAll(FetchMode::COLUMN); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
3 |
|
$qb->resetQueryParts(); |
|
369
|
|
|
|
|
370
|
3 |
|
$qb ->select('b.*') |
|
371
|
3 |
|
->fromPrefix('system_block', 'b') |
|
372
|
3 |
|
->where($eb->eq('b.isactive', $qb->createNamedParameter($isactive, ParameterType::INTEGER))); |
|
373
|
3 |
|
if (isset($visible)) { |
|
374
|
2 |
|
$qb->andWhere($eb->eq('b.visible', $qb->createNamedParameter($visible, ParameterType::INTEGER))); |
|
375
|
|
|
} |
|
376
|
3 |
|
if (isset($module_id)) { |
|
377
|
3 |
|
$qb ->fromPrefix('system_blockmodule', 'm') |
|
378
|
3 |
|
->andWhere($eb->eq('m.block_id', 'b.bid')); |
|
379
|
3 |
|
if (!empty($module_id)) { |
|
380
|
1 |
|
$in=array(); |
|
381
|
1 |
|
$in[]=0; |
|
382
|
1 |
|
$in[]=(int)($module_id); |
|
383
|
1 |
|
if ($toponlyblock) { |
|
384
|
1 |
|
$in[]=(int)(-1); |
|
385
|
|
|
} |
|
386
|
|
|
} else { |
|
387
|
3 |
|
if ($toponlyblock) { |
|
388
|
|
|
$in=array(0, -1); |
|
389
|
|
|
} else { |
|
390
|
3 |
|
$in=0; |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
3 |
|
if (is_array($in)) { |
|
394
|
1 |
|
$qb->andWhere($eb->in('m.module_id', $in)); |
|
395
|
|
|
} else { |
|
396
|
3 |
|
$qb->andWhere($eb->eq('m.module_id', $in)); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
3 |
|
if (!empty($blockids)) { |
|
400
|
3 |
|
$qb->andWhere($eb->in('b.bid', $blockids)); |
|
401
|
|
|
} |
|
402
|
3 |
|
$qb->orderBy($orderby); |
|
403
|
3 |
|
$result = $qb->execute(); |
|
404
|
3 |
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
405
|
3 |
|
$block = new XoopsBlock($myrow); |
|
406
|
3 |
|
$ret[$myrow['bid']] = $block; |
|
407
|
3 |
|
unset($block); |
|
408
|
|
|
} |
|
409
|
3 |
|
return $ret; |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* XoopsBlock::getNonGroupedBlocks() |
|
414
|
|
|
* |
|
415
|
|
|
* @param integer $module_id module id |
|
416
|
|
|
* @param boolean $toponlyblock only for top block |
|
417
|
|
|
* @param mixed $visible restrict by visible values |
|
418
|
|
|
* @param string $orderby comma separated list of columns to order by |
|
419
|
|
|
* @param integer $isactive restrict by isactive values |
|
420
|
|
|
* |
|
421
|
|
|
* @return array |
|
422
|
|
|
*/ |
|
423
|
1 |
|
public function getNonGroupedBlocks( |
|
424
|
|
|
$module_id = 0, |
|
425
|
|
|
$toponlyblock = false, |
|
426
|
|
|
$visible = null, |
|
427
|
|
|
$orderby = 'b.weight, m.block_id', |
|
428
|
|
|
$isactive = 1 |
|
429
|
|
|
) { |
|
430
|
1 |
|
$ret = array(); |
|
431
|
|
|
|
|
432
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
433
|
1 |
|
$eb = $qb->expr(); |
|
434
|
|
|
|
|
435
|
1 |
|
$qb ->select('DISTINCT(bid)') |
|
436
|
1 |
|
->fromPrefix('system_block', null); |
|
437
|
1 |
|
$result = $qb->execute(); |
|
438
|
1 |
|
$bids = $result->fetchAll(FetchMode::COLUMN); |
|
439
|
|
|
|
|
440
|
1 |
|
$qb->resetQueryParts(); |
|
441
|
|
|
|
|
442
|
1 |
|
$qb ->select('DISTINCT(p.gperm_itemid)') |
|
443
|
1 |
|
->fromPrefix('system_permission', 'p') |
|
444
|
1 |
|
->fromPrefix('system_group', 'g') |
|
445
|
1 |
|
->where($eb->eq('g.groupid', 'p.gperm_groupid')) |
|
446
|
1 |
|
->andWhere($eb->eq('p.gperm_name', $eb->literal('block_read'))); |
|
447
|
1 |
|
$result = $qb->execute(); |
|
448
|
1 |
|
$grouped = $result->fetchAll(FetchMode::COLUMN); |
|
449
|
|
|
|
|
450
|
1 |
|
$non_grouped = array_diff($bids, $grouped); |
|
451
|
|
|
|
|
452
|
1 |
|
if (!empty($non_grouped)) { |
|
453
|
|
|
$qb->resetQueryParts(); |
|
454
|
|
|
|
|
455
|
|
|
$qb ->select('b.*') |
|
456
|
|
|
->fromPrefix('system_block', 'b') |
|
457
|
|
|
->where($eb->eq('b.isactive', $qb->createNamedParameter($isactive, ParameterType::INTEGER))); |
|
458
|
|
|
if (isset($visible)) { |
|
459
|
|
|
$qb->andWhere($eb->eq('b.visible', $qb->createNamedParameter($visible, ParameterType::INTEGER))); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
if (isset($module_id)) { |
|
463
|
|
|
$qb ->fromPrefix('system_blockmodule', 'm') |
|
464
|
|
|
->andWhere($eb->eq('m.block_id', 'b.bid')); |
|
465
|
|
|
if (!empty($module_id)) { |
|
466
|
|
|
$in=array(); |
|
467
|
|
|
$in[]=0; |
|
468
|
|
|
$in[]=(int)($module_id); |
|
469
|
|
|
if ($toponlyblock) { |
|
470
|
|
|
$in[]=(int)(-1); |
|
471
|
|
|
} |
|
472
|
|
|
} else { |
|
473
|
|
|
if ($toponlyblock) { |
|
474
|
|
|
$in=array(0, -1); |
|
475
|
|
|
} else { |
|
476
|
|
|
$in=0; |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
if (is_array($in)) { |
|
480
|
|
|
$qb->andWhere($eb->in('m.module_id', $in)); |
|
481
|
|
|
} else { |
|
482
|
|
|
$qb->andWhere($eb->eq('m.module_id', $in)); |
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
$qb->andWhere($eb->in('b.bid', $non_grouped)); |
|
486
|
|
|
$qb->orderBy($orderby); |
|
487
|
|
|
$result = $qb->execute(); |
|
488
|
|
|
while ($myrow = $result->fetch(FetchMode::ASSOCIATIVE)) { |
|
489
|
|
|
$block = new XoopsBlock($myrow); |
|
490
|
|
|
$ret[$myrow['bid']] = $block; |
|
491
|
|
|
unset($block); |
|
492
|
|
|
} |
|
493
|
|
|
} |
|
494
|
1 |
|
return $ret; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* XoopsBlock::countSimilarBlocks() |
|
499
|
|
|
* |
|
500
|
|
|
* @param int $moduleId module id |
|
501
|
|
|
* @param string $funcNum func number |
|
502
|
|
|
* @param string $showFunc show function |
|
503
|
|
|
* |
|
504
|
|
|
* @return int count |
|
505
|
|
|
*/ |
|
506
|
1 |
|
public function countSimilarBlocks($moduleId, $funcNum, $showFunc = null) |
|
507
|
|
|
{ |
|
508
|
1 |
|
$funcNum = (int)($funcNum); |
|
509
|
1 |
|
$moduleId = (int)($moduleId); |
|
510
|
1 |
|
if ($funcNum < 1 || $moduleId < 1) { |
|
511
|
|
|
// invalid query |
|
512
|
|
|
return 0; |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
516
|
1 |
|
$eb = $qb->expr(); |
|
517
|
|
|
|
|
518
|
1 |
|
$qb ->select('COUNT(*)') |
|
519
|
1 |
|
->fromPrefix('system_block', null) |
|
520
|
1 |
|
->where($eb->eq('mid', $qb->createNamedParameter($moduleId, ParameterType::INTEGER))) |
|
521
|
1 |
|
->andWhere($eb->eq('func_num', $qb->createNamedParameter($funcNum, ParameterType::INTEGER))); |
|
522
|
|
|
|
|
523
|
1 |
|
if (isset($showFunc)) { |
|
524
|
|
|
// showFunc is set for more strict comparison |
|
525
|
1 |
|
$qb->andWhere($eb->eq('show_func', $qb->createNamedParameter($showFunc, ParameterType::STRING))); |
|
526
|
|
|
} |
|
527
|
1 |
|
if (!$result = $qb->execute()) { |
|
528
|
|
|
return 0; |
|
529
|
|
|
} |
|
530
|
1 |
|
list ($count) = $result->fetch(FetchMode::NUMERIC); |
|
531
|
1 |
|
return $count; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* Aligns the content of a block |
|
536
|
|
|
* |
|
537
|
|
|
* @param integer $position order of content |
|
538
|
|
|
* 0 -> content in DB is positioned before the original content |
|
539
|
|
|
* 1 -> content in DB is positioned after the original content |
|
540
|
|
|
* @param string $content content |
|
541
|
|
|
* @param string $contentdb content from database |
|
542
|
|
|
* |
|
543
|
|
|
* @return string |
|
544
|
|
|
*/ |
|
545
|
1 |
|
public function buildContent($position, $content = "", $contentdb = "") |
|
546
|
|
|
{ |
|
547
|
1 |
|
$ret = ''; |
|
548
|
1 |
|
if ($position == 0) { |
|
549
|
1 |
|
$ret = $contentdb . $content; |
|
550
|
|
|
} else { |
|
551
|
1 |
|
if ($position == 1) { |
|
552
|
1 |
|
$ret = $content . $contentdb; |
|
553
|
|
|
} |
|
554
|
|
|
} |
|
555
|
1 |
|
return $ret; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
/** |
|
559
|
|
|
* Enter description here... appears to be unused? |
|
560
|
|
|
* |
|
561
|
|
|
* @param string $originaltitle original title |
|
562
|
|
|
* @param string $newtitle new title |
|
563
|
|
|
* |
|
564
|
|
|
* @return string title winner of the title war? |
|
565
|
|
|
*/ |
|
566
|
1 |
|
public function buildTitle($originaltitle, $newtitle = '') |
|
567
|
|
|
{ |
|
568
|
1 |
|
if ($newtitle != '') { |
|
569
|
1 |
|
$ret = $newtitle; |
|
570
|
|
|
} else { |
|
571
|
1 |
|
$ret = $originaltitle; |
|
572
|
|
|
} |
|
573
|
1 |
|
return $ret; |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
/************ system ***************/ |
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* get list of ids of block that a group has permission to views |
|
580
|
|
|
* |
|
581
|
|
|
* @param null|integer $groupid group |
|
582
|
|
|
* |
|
583
|
|
|
* @return int[] |
|
584
|
|
|
*/ |
|
585
|
1 |
|
public function getBlockByPerm($groupid) |
|
586
|
|
|
{ |
|
587
|
1 |
|
$ret = array(); |
|
588
|
1 |
|
if (isset($groupid)) { |
|
589
|
1 |
|
$qb = $this->db2->createXoopsQueryBuilder(); |
|
590
|
1 |
|
$eb = $qb->expr(); |
|
591
|
|
|
|
|
592
|
1 |
|
$qb ->select('DISTINCT(gperm_itemid)') |
|
593
|
1 |
|
->fromPrefix('system_permission', 'p') |
|
594
|
1 |
|
->fromPrefix('system_group', 'g') |
|
595
|
1 |
|
->where($eb->eq('p.gperm_name', $eb->literal('block_read'))) |
|
596
|
1 |
|
->andWhere('gperm_modid=1'); |
|
597
|
|
|
|
|
598
|
1 |
|
if (is_array($groupid)) { |
|
|
|
|
|
|
599
|
|
|
$qb->andWhere($eb->in('gperm_groupid', $groupid)); |
|
600
|
|
|
} else { |
|
601
|
1 |
|
if ((int)($groupid) > 0) { |
|
602
|
1 |
|
$qb->andWhere($eb->eq('gperm_groupid', $groupid)); |
|
603
|
|
|
} |
|
604
|
|
|
} |
|
605
|
|
|
|
|
606
|
1 |
|
$result = $qb->execute(); |
|
607
|
1 |
|
$blockids = $result->fetchAll(FetchMode::COLUMN); |
|
608
|
1 |
|
return $blockids; |
|
609
|
|
|
} |
|
610
|
1 |
|
return $ret; |
|
611
|
|
|
} |
|
612
|
|
|
} |
|
613
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.