Total Complexity | 124 |
Total Lines | 925 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 0 |
Complex classes like XoopsBlock often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use XoopsBlock, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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 = '') |
||
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 | * Valid 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 = '') |
||
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 = '') |
||
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 = '') |
||
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') |
||
363 | } |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * (HTML-) form for setting the options of the block |
||
368 | * |
||
369 | * @return string HTML for the form, FALSE if not defined for this block |
||
370 | */ |
||
371 | public function getOptions() |
||
397 | } |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * @return bool |
||
402 | */ |
||
403 | public function isCustom() |
||
404 | { |
||
405 | return in_array( |
||
406 | $this->getVar('block_type'), |
||
407 | [ |
||
408 | 'C', |
||
409 | 'E', |
||
410 | ], |
||
411 | ); |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * These methods are for compatibility with the pre 2.5.11 class/xoopsblock.php |
||
416 | * class/xoopsblock.php defined its own XoopsBlock class, making it impossible |
||
417 | * to use with anything that used the handler provided in kernel/block.php |
||
418 | * |
||
419 | * In addition to the actual data, the old XoopsBlock contained what should be |
||
420 | * considered handler logic. |
||
421 | * |
||
422 | * It appears that class/xoopsblock.php came first, but a conversion to the kernel |
||
423 | * handler was never completed. |
||
424 | * |
||
425 | * These methods should all be considered deprecated. |
||
426 | */ |
||
427 | |||
428 | /** |
||
429 | * Load $id |
||
430 | * |
||
431 | * @param int $id |
||
432 | * |
||
433 | * @deprecated |
||
434 | */ |
||
435 | public function load($id) |
||
436 | { |
||
437 | $id = (int) $id; |
||
438 | /** @var XoopsBlockHandler $blkhandler */ |
||
439 | $blkhandler = xoops_getHandler('block'); |
||
440 | $obj = $blkhandler->get($id); |
||
441 | foreach (array_keys($obj->getVars()) as $i) { |
||
442 | $this->assignVar($i, $obj->getVar($i, 'n')); |
||
443 | } |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * Store Block Data to Database |
||
448 | * |
||
449 | * @return int|false id of inserted block, or false on failure |
||
450 | * |
||
451 | * @deprecated |
||
452 | */ |
||
453 | public function store() |
||
454 | { |
||
455 | /** @var XoopsBlockHandler $blkhandler */ |
||
456 | $blkhandler = xoops_getHandler('block'); |
||
457 | if (false === $blkhandler->insert($this)) { |
||
458 | return false; |
||
459 | } |
||
460 | return (int) $this->bid(); |
||
461 | } |
||
462 | |||
463 | /** |
||
464 | * Delete an ID from the database |
||
465 | * |
||
466 | * @return bool |
||
467 | * |
||
468 | * @deprecated |
||
469 | */ |
||
470 | public function delete() |
||
475 | } |
||
476 | |||
477 | /** |
||
478 | * Build Block |
||
479 | * |
||
480 | * @return mixed |
||
481 | * |
||
482 | * @deprecated |
||
483 | */ |
||
484 | public function buildBlock() |
||
485 | { |
||
486 | global $xoopsConfig, $xoopsOption, $xoTheme; |
||
487 | $block = []; |
||
488 | if (!$this->isCustom()) { |
||
489 | // get block display function |
||
490 | $show_func = $this->getVar('show_func'); |
||
491 | if (!$show_func) { |
||
492 | return false; |
||
493 | } |
||
494 | if (!file_exists($func_file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file')))) { |
||
495 | return false; |
||
496 | } |
||
497 | // must get lang files b4 including the file |
||
498 | // some modules require it for code that is outside the function |
||
499 | xoops_loadLanguage('blocks', $this->getVar('dirname')); |
||
500 | include_once $func_file; |
||
501 | |||
502 | if (function_exists($show_func)) { |
||
503 | // execute the function |
||
504 | $options = explode('|', $this->getVar('options')); |
||
505 | $block = $show_func($options); |
||
506 | if (!$block) { |
||
507 | return false; |
||
508 | } |
||
509 | } else { |
||
510 | return false; |
||
511 | } |
||
512 | } else { |
||
513 | // it is a custom block, so just return the contents |
||
514 | $block['content'] = $this->getContent('s', $this->getVar('c_type')); |
||
515 | if (empty($block['content'])) { |
||
516 | return false; |
||
517 | } |
||
518 | } |
||
519 | |||
520 | return $block; |
||
521 | } |
||
522 | |||
523 | /* |
||
524 | * Aligns the content of a block |
||
525 | * If position is 0, content in DB is positioned |
||
526 | * before the original content |
||
527 | * If position is 1, content in DB is positioned |
||
528 | * after the original content |
||
529 | */ |
||
530 | /** |
||
531 | * @param $position |
||
532 | * @param string $content |
||
533 | * @param string $contentdb |
||
534 | * |
||
535 | * @return string |
||
536 | * |
||
537 | * @deprecated |
||
538 | */ |
||
539 | public function buildContent($position, $content = '', $contentdb = '') |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * Enter description here... |
||
553 | * |
||
554 | * @param string $originaltitle |
||
555 | * @param string $newtitle |
||
556 | * @return string title |
||
557 | * |
||
558 | * @deprecated |
||
559 | */ |
||
560 | public function buildTitle($originaltitle, $newtitle = '') |
||
561 | { |
||
562 | $ret = $originaltitle; |
||
563 | if ($newtitle != '') { |
||
564 | $ret = $newtitle; |
||
565 | } |
||
566 | |||
567 | return $ret; |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * get all the blocks that match the supplied parameters |
||
572 | * @param int|array $groupid groupid (can be an array) |
||
573 | * @param bool $asobject |
||
574 | * @param null|string $side 0: sideblock - left |
||
575 | * 1: sideblock - right |
||
576 | * 2: sideblock - left and right |
||
577 | * 3: centerblock - left |
||
578 | * 4: centerblock - right |
||
579 | * 5: centerblock - center |
||
580 | * 6: centerblock - left, right, center |
||
581 | * @param $visible 0: not visible 1: visible |
||
582 | * @param string $orderby order of the blocks |
||
583 | * @param int $isactive |
||
584 | * @returns array of block objects |
||
585 | * |
||
586 | * @deprecated |
||
587 | */ |
||
588 | public static function getAllBlocksByGroup($groupid, $asobject = true, $side = null, $visible = null, $orderby = 'b.weight,b.bid', $isactive = 1) |
||
647 | } |
||
648 | |||
649 | /** |
||
650 | * XoopsBlock::getAllBlocks() |
||
651 | * |
||
652 | * @param string $rettype |
||
653 | * @param mixed $side |
||
654 | * @param mixed $visible |
||
655 | * @param string $orderby |
||
656 | * @param integer $isactive |
||
657 | * @return array |
||
658 | * |
||
659 | * @deprecated |
||
660 | */ |
||
661 | public function getAllBlocks($rettype = 'object', $side = null, $visible = null, $orderby = 'side,weight,bid', $isactive = 1) |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * XoopsBlock::getByModule() |
||
733 | * |
||
734 | * @param mixed $moduleid |
||
735 | * @param mixed $asobject |
||
736 | * @return array |
||
737 | */ |
||
738 | public static function getByModule($moduleid, $asobject = true) |
||
739 | { |
||
740 | $moduleid = (int) $moduleid; |
||
741 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
742 | if ($asobject == true) { |
||
743 | $sql = $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid; |
||
744 | } else { |
||
745 | $sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid; |
||
746 | } |
||
747 | $result = $db->query($sql); |
||
748 | if (!$db->isResultSet($result)) { |
||
749 | throw new \RuntimeException( |
||
750 | \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), |
||
751 | E_USER_ERROR, |
||
752 | ); |
||
753 | } |
||
754 | $ret = []; |
||
755 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
756 | if ($asobject) { |
||
757 | $ret[] = new XoopsBlock($myrow); |
||
758 | } else { |
||
759 | $ret[] = $myrow['bid']; |
||
760 | } |
||
761 | } |
||
762 | |||
763 | return $ret; |
||
764 | } |
||
765 | |||
766 | /** |
||
767 | * XoopsBlock::getAllByGroupModule() |
||
768 | * |
||
769 | * @param mixed $groupid |
||
770 | * @param integer $module_id |
||
771 | * @param mixed $toponlyblock |
||
772 | * @param mixed $visible |
||
773 | * @param string $orderby |
||
774 | * @param integer $isactive |
||
775 | * @return array |
||
776 | * |
||
777 | * @deprecated (This also appears, dead, in XoopsBlockHandler) |
||
778 | */ |
||
779 | public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
||
780 | { |
||
781 | $isactive = (int) $isactive; |
||
782 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
783 | $ret = []; |
||
784 | if (isset($groupid)) { |
||
785 | $sql = 'SELECT DISTINCT gperm_itemid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name = 'block_read' AND gperm_modid = 1"; |
||
786 | if (is_array($groupid)) { |
||
787 | $sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ')'; |
||
788 | } else { |
||
789 | if ((int) $groupid > 0) { |
||
790 | $sql .= ' AND gperm_groupid=' . (int) $groupid; |
||
791 | } |
||
792 | } |
||
793 | $result = $db->query($sql); |
||
794 | if (!$db->isResultSet($result)) { |
||
795 | throw new \RuntimeException( |
||
796 | \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), |
||
797 | E_USER_ERROR, |
||
798 | ); |
||
799 | } |
||
800 | $blockids = []; |
||
801 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
802 | $blockids[] = $myrow['gperm_itemid']; |
||
803 | } |
||
804 | if (empty($blockids)) { |
||
805 | return $blockids; |
||
806 | } |
||
807 | } |
||
808 | $sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b |
||
809 | JOIN ' . $db->prefix('block_module_link') . ' m ON m.block_id = b.bid |
||
810 | LEFT JOIN ' . $db->prefix('modules') . ' mo ON mo.mid = b.mid |
||
811 | WHERE b.isactive =' . $isactive . ' AND (mo.isactive =' . $isactive . ' OR b.mid = 0)'; |
||
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 | if (!empty($blockids)) { |
||
830 | $sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')'; |
||
831 | } |
||
832 | $sql .= ' ORDER BY ' . $orderby; |
||
833 | $result = $db->query($sql); |
||
834 | if (!$db->isResultSet($result)) { |
||
835 | throw new \RuntimeException( |
||
836 | \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), |
||
837 | E_USER_ERROR, |
||
838 | ); |
||
839 | } |
||
840 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
841 | $block = new XoopsBlock($myrow); |
||
842 | $ret[$myrow['bid']] = &$block; |
||
843 | unset($block); |
||
844 | } |
||
845 | |||
846 | return $ret; |
||
847 | } |
||
848 | |||
849 | /** |
||
850 | * XoopsBlock::getNonGroupedBlocks() |
||
851 | * |
||
852 | * @param integer $module_id |
||
853 | * @param mixed $toponlyblock |
||
854 | * @param mixed $visible |
||
855 | * @param string $orderby |
||
856 | * @param integer $isactive |
||
857 | * @return array |
||
858 | * |
||
859 | * @deprecated |
||
860 | */ |
||
861 | public function getNonGroupedBlocks($module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
||
862 | { |
||
863 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
864 | $ret = []; |
||
865 | $bids = []; |
||
866 | $sql = 'SELECT DISTINCT(bid) from ' . $db->prefix('newblocks'); |
||
867 | $result = $db->query($sql); |
||
868 | if ($db->isResultSet($result)) { |
||
869 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
870 | $bids[] = $myrow['bid']; |
||
871 | } |
||
872 | } |
||
873 | |||
874 | $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'"; |
||
875 | $grouped = []; |
||
876 | $result = $db->query($sql); |
||
877 | if ($db->isResultSet($result)) { |
||
878 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
879 | $grouped[] = $myrow['gperm_itemid']; |
||
880 | } |
||
881 | } |
||
882 | |||
883 | |||
884 | $non_grouped = array_diff($bids, $grouped); |
||
885 | if (!empty($non_grouped)) { |
||
886 | $sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
||
887 | $sql .= ' AND b.isactive=' . (int) $isactive; |
||
888 | if (isset($visible)) { |
||
889 | $sql .= ' AND b.visible=' . (int) $visible; |
||
890 | } |
||
891 | if (!isset($module_id)) { |
||
892 | } elseif (!empty($module_id)) { |
||
893 | $sql .= ' AND m.module_id IN (0,' . (int) $module_id; |
||
894 | if ($toponlyblock) { |
||
895 | $sql .= ',-1'; |
||
896 | } |
||
897 | $sql .= ')'; |
||
898 | } else { |
||
899 | if ($toponlyblock) { |
||
900 | $sql .= ' AND m.module_id IN (0,-1)'; |
||
901 | } else { |
||
902 | $sql .= ' AND m.module_id=0'; |
||
903 | } |
||
904 | } |
||
905 | $sql .= ' AND b.bid IN (' . implode(',', $non_grouped) . ')'; |
||
906 | $sql .= ' ORDER BY ' . $orderby; |
||
907 | $result = $db->query($sql); |
||
908 | if (!$db->isResultSet($result)) { |
||
909 | throw new \RuntimeException( |
||
910 | \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), |
||
911 | E_USER_ERROR, |
||
912 | ); |
||
913 | } |
||
914 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
915 | $block = new XoopsBlock($myrow); |
||
916 | $ret[$myrow['bid']] = & $block; |
||
917 | unset($block); |
||
918 | } |
||
919 | } |
||
920 | |||
921 | return $ret; |
||
922 | } |
||
923 | |||
924 | /** |
||
925 | * XoopsBlock::countSimilarBlocks() |
||
926 | * |
||
927 | * @param mixed $moduleId |
||
928 | * @param mixed $funcNum |
||
929 | * @param mixed $showFunc |
||
930 | * @return int |
||
931 | * |
||
932 | * @deprecated |
||
933 | */ |
||
934 | public function countSimilarBlocks($moduleId, $funcNum, $showFunc = null) |
||
956 | } |
||
957 | } |
||
958 | |||
959 | /** |
||
1259 |