| Total Complexity | 124 |
| Total Lines | 902 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 = '') |
||
| 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 | break; |
||
| 359 | case 'e': |
||
| 360 | return $this->getVar('content', 'e'); |
||
| 361 | break; |
||
| 362 | default: |
||
| 363 | return $this->getVar('content', 'n'); |
||
| 364 | break; |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * (HTML-) form for setting the options of the block |
||
| 370 | * |
||
| 371 | * @return string HTML for the form, FALSE if not defined for this block |
||
| 372 | */ |
||
| 373 | public function getOptions() |
||
| 374 | { |
||
| 375 | if (!$this->isCustom()) { |
||
| 376 | $edit_func = $this->getVar('edit_func'); |
||
| 377 | if (!$edit_func) { |
||
| 378 | return false; |
||
| 379 | } |
||
| 380 | if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file'))) { |
||
| 381 | if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php')) { |
||
| 382 | include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php'; |
||
| 383 | } elseif (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/english/blocks.php')) { |
||
| 384 | include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/english/blocks.php'; |
||
| 385 | } |
||
| 386 | include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file'); |
||
| 387 | $options = explode('|', $this->getVar('options')); |
||
| 388 | $edit_form = $edit_func($options); |
||
| 389 | if (!$edit_form) { |
||
| 390 | return false; |
||
| 391 | } |
||
| 392 | |||
| 393 | return $edit_form; |
||
| 394 | } else { |
||
| 395 | return false; |
||
| 396 | } |
||
| 397 | } else { |
||
| 398 | return false; |
||
| 399 | } |
||
| 400 | } |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return bool |
||
| 404 | */ |
||
| 405 | public function isCustom() |
||
| 406 | { |
||
| 407 | return in_array($this->getVar('block_type'), array( |
||
| 408 | 'C', |
||
| 409 | 'E')); |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * These methods are for compatibility with the pre 2.5.11 class/xoopsblock.php |
||
| 414 | * class/xoopsblock.php defined its own XoopsBlock class, making it impossible |
||
| 415 | * to use with anything that used the handler provided in kernel/block.php |
||
| 416 | * |
||
| 417 | * In addition to the actual data, the old XoopsBlock contained what should be |
||
| 418 | * considered handler logic. |
||
| 419 | * |
||
| 420 | * It appears that class/xoopsblock.php came first, but a conversion to the kernel |
||
| 421 | * handler was never completed. |
||
| 422 | * |
||
| 423 | * These methods should all be considered deprecated. |
||
| 424 | */ |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Load $id |
||
| 428 | * |
||
| 429 | * @param int $id |
||
| 430 | * |
||
| 431 | * @deprecated |
||
| 432 | */ |
||
| 433 | public function load($id) |
||
| 434 | { |
||
| 435 | $id = (int)$id; |
||
| 436 | /** @var XoopsBlockHandler $blkhandler */ |
||
| 437 | $blkhandler = xoops_getHandler('block'); |
||
| 438 | $obj = $blkhandler->get($id); |
||
| 439 | foreach (array_keys($obj->getVars()) as $i) { |
||
| 440 | $this->assignVar($i, $obj->getVar($i, 'n')); |
||
| 441 | } |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Store Block Data to Database |
||
| 446 | * |
||
| 447 | * @return int|false id of inserted block, or false on failure |
||
| 448 | * |
||
| 449 | * @deprecated |
||
| 450 | */ |
||
| 451 | public function store() |
||
| 452 | { |
||
| 453 | /** @var XoopsBlockHandler $blkhandler */ |
||
| 454 | $blkhandler = xoops_getHandler('block'); |
||
| 455 | if (false === $blkhandler->insert($this)) { |
||
| 456 | return false; |
||
| 457 | } |
||
| 458 | return (int) $this->bid(); |
||
| 459 | } |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Delete a ID from the database |
||
| 463 | * |
||
| 464 | * @return bool |
||
| 465 | * |
||
| 466 | * @deprecated |
||
| 467 | */ |
||
| 468 | public function delete() |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Build Block |
||
| 477 | * |
||
| 478 | * @return mixed |
||
| 479 | * |
||
| 480 | * @deprecated |
||
| 481 | */ |
||
| 482 | public function buildBlock() |
||
| 483 | { |
||
| 484 | global $xoopsConfig, $xoopsOption, $xoTheme; |
||
| 485 | $block = array(); |
||
| 486 | if (!$this->isCustom()) { |
||
| 487 | // get block display function |
||
| 488 | $show_func = $this->getVar('show_func'); |
||
| 489 | if (!$show_func) { |
||
| 490 | return false; |
||
| 491 | } |
||
| 492 | if (!file_exists($func_file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file')))) { |
||
| 493 | return false; |
||
| 494 | } |
||
| 495 | // must get lang files b4 including the file |
||
| 496 | // some modules require it for code that is outside the function |
||
| 497 | xoops_loadLanguage('blocks', $this->getVar('dirname')); |
||
| 498 | include_once $func_file; |
||
| 499 | |||
| 500 | if (function_exists($show_func)) { |
||
| 501 | // execute the function |
||
| 502 | $options = explode('|', $this->getVar('options')); |
||
| 503 | $block = $show_func($options); |
||
| 504 | if (!$block) { |
||
| 505 | return false; |
||
| 506 | } |
||
| 507 | } else { |
||
| 508 | return false; |
||
| 509 | } |
||
| 510 | } else { |
||
| 511 | // it is a custom block, so just return the contents |
||
| 512 | $block['content'] = $this->getContent('s', $this->getVar('c_type')); |
||
| 513 | if (empty($block['content'])) { |
||
| 514 | return false; |
||
| 515 | } |
||
| 516 | } |
||
| 517 | |||
| 518 | return $block; |
||
| 519 | } |
||
| 520 | |||
| 521 | /* |
||
| 522 | * Aligns the content of a block |
||
| 523 | * If position is 0, content in DB is positioned |
||
| 524 | * before the original content |
||
| 525 | * If position is 1, content in DB is positioned |
||
| 526 | * after the original content |
||
| 527 | */ |
||
| 528 | /** |
||
| 529 | * @param $position |
||
| 530 | * @param string $content |
||
| 531 | * @param string $contentdb |
||
| 532 | * |
||
| 533 | * @return string |
||
| 534 | * |
||
| 535 | * @deprecated |
||
| 536 | */ |
||
| 537 | public function buildContent($position, $content = '', $contentdb = '') |
||
| 547 | } |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Enter description here... |
||
| 551 | * |
||
| 552 | * @param string $originaltitle |
||
| 553 | * @param string $newtitle |
||
| 554 | * @return string title |
||
| 555 | * |
||
| 556 | * @deprecated |
||
| 557 | */ |
||
| 558 | public function buildTitle($originaltitle, $newtitle = '') |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * get all the blocks that match the supplied parameters |
||
| 570 | * @param int|array $groupid groupid (can be an array) |
||
| 571 | * @param bool $asobject |
||
| 572 | * @param null|string $side 0: sideblock - left |
||
| 573 | * 1: sideblock - right |
||
| 574 | * 2: sideblock - left and right |
||
| 575 | * 3: centerblock - left |
||
| 576 | * 4: centerblock - right |
||
| 577 | * 5: centerblock - center |
||
| 578 | * 6: centerblock - left, right, center |
||
| 579 | * @param $visible 0: not visible 1: visible |
||
| 580 | * @param string $orderby order of the blocks |
||
| 581 | * @param int $isactive |
||
| 582 | * @returns array of block objects |
||
| 583 | * |
||
| 584 | * @deprecated |
||
| 585 | */ |
||
| 586 | public static function getAllBlocksByGroup($groupid, $asobject = true, $side = null, $visible = null, $orderby = 'b.weight,b.bid', $isactive = 1) |
||
| 587 | { |
||
| 588 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 589 | $ret = array(); |
||
| 590 | $sql = 'SELECT b.* '; |
||
| 591 | if (!$asobject) { |
||
| 592 | $sql = 'SELECT b.bid '; |
||
| 593 | } |
||
| 594 | $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"; |
||
| 595 | if (is_array($groupid)) { |
||
| 596 | $sql .= ' AND (l.gperm_groupid=' . $groupid[0] . ''; |
||
| 597 | $size = count($groupid); |
||
| 598 | if ($size > 1) { |
||
| 599 | for ($i = 1; $i < $size; ++$i) { |
||
| 600 | $sql .= ' OR l.gperm_groupid=' . $groupid[$i] . ''; |
||
| 601 | } |
||
| 602 | } |
||
| 603 | $sql .= ')'; |
||
| 604 | } else { |
||
| 605 | $sql .= ' AND l.gperm_groupid=' . $groupid . ''; |
||
| 606 | } |
||
| 607 | $sql .= ' AND b.isactive=' . $isactive; |
||
| 608 | if (isset($side)) { |
||
| 609 | // get both sides in sidebox? (some themes need this) |
||
| 610 | if ($side == XOOPS_SIDEBLOCK_BOTH) { |
||
| 611 | $side = '(b.side=0 OR b.side=1)'; |
||
| 612 | } elseif ($side == XOOPS_CENTERBLOCK_ALL) { |
||
| 613 | $side = '(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )'; |
||
| 614 | } elseif ($side == XOOPS_FOOTERBLOCK_ALL) { |
||
| 615 | $side = '(b.side=10 OR b.side=11 OR b.side=12 )'; |
||
| 616 | } else { |
||
| 617 | $side = 'b.side=' . $side; |
||
| 618 | } |
||
| 619 | $sql .= ' AND ' . $side; |
||
| 620 | } |
||
| 621 | if (isset($visible)) { |
||
| 622 | $sql .= " AND b.visible=$visible"; |
||
| 623 | } |
||
| 624 | $sql .= " ORDER BY $orderby"; |
||
| 625 | $result = $db->query($sql); |
||
| 626 | if (!$db->isResultSet($result)) { |
||
| 627 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 628 | } |
||
| 629 | $added = array(); |
||
| 630 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 631 | if (!in_array($myrow['bid'], $added)) { |
||
| 632 | if (!$asobject) { |
||
| 633 | $ret[] = $myrow['bid']; |
||
| 634 | } else { |
||
| 635 | $ret[] = new XoopsBlock($myrow); |
||
| 636 | } |
||
| 637 | $added[] = $myrow['bid']; |
||
| 638 | } |
||
| 639 | } |
||
| 640 | |||
| 641 | return $ret; |
||
| 642 | } |
||
| 643 | |||
| 644 | /** |
||
| 645 | * XoopsBlock::getAllBlocks() |
||
| 646 | * |
||
| 647 | * @param string $rettype |
||
| 648 | * @param mixed $side |
||
| 649 | * @param mixed $visible |
||
| 650 | * @param string $orderby |
||
| 651 | * @param integer $isactive |
||
| 652 | * @return array |
||
| 653 | * |
||
| 654 | * @deprecated |
||
| 655 | */ |
||
| 656 | public function getAllBlocks($rettype = 'object', $side = null, $visible = null, $orderby = 'side,weight,bid', $isactive = 1) |
||
| 657 | { |
||
| 658 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 659 | $ret = array(); |
||
| 660 | $where_query = ' WHERE isactive=' . $isactive; |
||
| 661 | if (isset($side)) { |
||
| 662 | // get both sides in sidebox? (some themes need this) |
||
| 663 | if ($side == XOOPS_SIDEBLOCK_BOTH) { |
||
| 664 | $side = '(side=0 OR side=1)'; |
||
| 665 | } elseif ($side == XOOPS_CENTERBLOCK_ALL) { |
||
| 666 | $side = '(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)'; |
||
| 667 | } elseif ($side == XOOPS_FOOTERBLOCK_ALL) { |
||
| 668 | $side = '(side=10 OR side=11 OR side=12)'; |
||
| 669 | } else { |
||
| 670 | $side = 'side=' . $side; |
||
| 671 | } |
||
| 672 | $where_query .= ' AND ' . $side; |
||
| 673 | } |
||
| 674 | if (isset($visible)) { |
||
| 675 | $where_query .= ' AND visible=.' . $visible; |
||
| 676 | } |
||
| 677 | $where_query .= ' ORDER BY ' . $orderby; |
||
| 678 | switch ($rettype) { |
||
| 679 | case 'object': |
||
| 680 | $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query; |
||
| 681 | $result = $db->query($sql); |
||
| 682 | if (!$db->isResultSet($result)) { |
||
| 683 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 684 | } |
||
| 685 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 686 | $ret[] = new XoopsBlock($myrow); |
||
| 687 | } |
||
| 688 | break; |
||
| 689 | case 'list': |
||
| 690 | $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query; |
||
| 691 | $result = $db->query($sql); |
||
| 692 | if (!$db->isResultSet($result)) { |
||
| 693 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 694 | } |
||
| 695 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 696 | $block = new XoopsBlock($myrow); |
||
| 697 | $title = $block->getVar('title'); |
||
| 698 | $title = empty($title) ? $block->getVar('name') : $title; |
||
| 699 | $ret[$block->getVar('bid')] = $title; |
||
| 700 | } |
||
| 701 | break; |
||
| 702 | case 'id': |
||
| 703 | $sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . '' . $where_query; |
||
| 704 | $result = $db->query($sql); |
||
| 705 | if (!$db->isResultSet($result)) { |
||
| 706 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 707 | } |
||
| 708 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 709 | $ret[] = $myrow['bid']; |
||
| 710 | } |
||
| 711 | break; |
||
| 712 | } |
||
| 713 | |||
| 714 | return $ret; |
||
| 715 | } |
||
| 716 | |||
| 717 | /** |
||
| 718 | * XoopsBlock::getByModule() |
||
| 719 | * |
||
| 720 | * @param mixed $moduleid |
||
| 721 | * @param mixed $asobject |
||
| 722 | * @return array |
||
| 723 | * |
||
| 724 | * @deprecated (This also appears, dead, in XoopsBlockHandler) |
||
| 725 | */ |
||
| 726 | public static function getByModule($moduleid, $asobject = true) |
||
| 727 | { |
||
| 728 | $moduleid = (int)$moduleid; |
||
| 729 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 730 | if ($asobject == true) { |
||
| 731 | $sql = $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid; |
||
| 732 | } else { |
||
| 733 | $sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid; |
||
| 734 | } |
||
| 735 | $result = $db->query($sql); |
||
| 736 | if (!$db->isResultSet($result)) { |
||
| 737 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 738 | } |
||
| 739 | $ret = array(); |
||
| 740 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 741 | if ($asobject) { |
||
| 742 | $ret[] = new XoopsBlock($myrow); |
||
| 743 | } else { |
||
| 744 | $ret[] = $myrow['bid']; |
||
| 745 | } |
||
| 746 | } |
||
| 747 | |||
| 748 | return $ret; |
||
| 749 | } |
||
| 750 | |||
| 751 | /** |
||
| 752 | * XoopsBlock::getAllByGroupModule() |
||
| 753 | * |
||
| 754 | * @param mixed $groupid |
||
| 755 | * @param integer $module_id |
||
| 756 | * @param mixed $toponlyblock |
||
| 757 | * @param mixed $visible |
||
| 758 | * @param string $orderby |
||
| 759 | * @param integer $isactive |
||
| 760 | * @return array |
||
| 761 | * |
||
| 762 | * @deprecated (This also appears, dead, in XoopsBlockHandler) |
||
| 763 | */ |
||
| 764 | public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
||
| 765 | { |
||
| 766 | $isactive = (int)$isactive; |
||
| 767 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 768 | $ret = array(); |
||
| 769 | if (isset($groupid)) { |
||
| 770 | $sql = 'SELECT DISTINCT gperm_itemid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name = 'block_read' AND gperm_modid = 1"; |
||
| 771 | if (is_array($groupid)) { |
||
| 772 | $sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ')'; |
||
| 773 | } else { |
||
| 774 | if ((int)$groupid > 0) { |
||
| 775 | $sql .= ' AND gperm_groupid=' . (int)$groupid; |
||
| 776 | } |
||
| 777 | } |
||
| 778 | $result = $db->query($sql); |
||
| 779 | if (!$db->isResultSet($result)) { |
||
| 780 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 781 | } |
||
| 782 | $blockids = array(); |
||
| 783 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 784 | $blockids[] = $myrow['gperm_itemid']; |
||
| 785 | } |
||
| 786 | if (empty($blockids)) { |
||
| 787 | return $blockids; |
||
| 788 | } |
||
| 789 | } |
||
| 790 | $sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
||
| 791 | $sql .= ' AND b.isactive=' . $isactive; |
||
| 792 | if (isset($visible)) { |
||
| 793 | $sql .= ' AND b.visible=' . (int)$visible; |
||
| 794 | } |
||
| 795 | if (!isset($module_id)) { |
||
| 796 | } elseif (!empty($module_id)) { |
||
| 797 | $sql .= ' AND m.module_id IN (0,' . (int)$module_id; |
||
| 798 | if ($toponlyblock) { |
||
| 799 | $sql .= ',-1'; |
||
| 800 | } |
||
| 801 | $sql .= ')'; |
||
| 802 | } else { |
||
| 803 | if ($toponlyblock) { |
||
| 804 | $sql .= ' AND m.module_id IN (0,-1)'; |
||
| 805 | } else { |
||
| 806 | $sql .= ' AND m.module_id=0'; |
||
| 807 | } |
||
| 808 | } |
||
| 809 | if (!empty($blockids)) { |
||
| 810 | $sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')'; |
||
| 811 | } |
||
| 812 | $sql .= ' ORDER BY ' . $orderby; |
||
| 813 | $result = $db->query($sql); |
||
| 814 | if (!$db->isResultSet($result)) { |
||
| 815 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 816 | } |
||
| 817 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 818 | $block = new XoopsBlock($myrow); |
||
| 819 | $ret[$myrow['bid']] = &$block; |
||
| 820 | unset($block); |
||
| 821 | } |
||
| 822 | |||
| 823 | return $ret; |
||
| 824 | } |
||
| 825 | |||
| 826 | /** |
||
| 827 | * XoopsBlock::getNonGroupedBlocks() |
||
| 828 | * |
||
| 829 | * @param integer $module_id |
||
| 830 | * @param mixed $toponlyblock |
||
| 831 | * @param mixed $visible |
||
| 832 | * @param string $orderby |
||
| 833 | * @param integer $isactive |
||
| 834 | * @return array |
||
| 835 | * |
||
| 836 | * @deprecated |
||
| 837 | */ |
||
| 838 | public function getNonGroupedBlocks($module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
||
| 839 | { |
||
| 840 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 841 | $ret = array(); |
||
| 842 | $bids = array(); |
||
| 843 | $sql = 'SELECT DISTINCT(bid) from ' . $db->prefix('newblocks'); |
||
| 844 | $result = $db->query($sql); |
||
| 845 | if ($db->isResultSet($result)) { |
||
| 846 | // \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 847 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 848 | $bids[] = $myrow['bid']; |
||
| 849 | } |
||
| 850 | } |
||
| 851 | |||
| 852 | $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'"; |
||
| 853 | $grouped = array(); |
||
| 854 | $result = $db->query($sql); |
||
| 855 | if ($db->isResultSet($result)) { |
||
| 856 | // \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 857 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 858 | $grouped[] = $myrow['gperm_itemid']; |
||
| 859 | } |
||
| 860 | } |
||
| 861 | |||
| 862 | |||
| 863 | $non_grouped = array_diff($bids, $grouped); |
||
| 864 | if (!empty($non_grouped)) { |
||
| 865 | $sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
||
| 866 | $sql .= ' AND b.isactive=' . (int)$isactive; |
||
| 867 | if (isset($visible)) { |
||
| 868 | $sql .= ' AND b.visible=' . (int)$visible; |
||
| 869 | } |
||
| 870 | if (!isset($module_id)) { |
||
| 871 | } elseif (!empty($module_id)) { |
||
| 872 | $sql .= ' AND m.module_id IN (0,' . (int)$module_id; |
||
| 873 | if ($toponlyblock) { |
||
| 874 | $sql .= ',-1'; |
||
| 875 | } |
||
| 876 | $sql .= ')'; |
||
| 877 | } else { |
||
| 878 | if ($toponlyblock) { |
||
| 879 | $sql .= ' AND m.module_id IN (0,-1)'; |
||
| 880 | } else { |
||
| 881 | $sql .= ' AND m.module_id=0'; |
||
| 882 | } |
||
| 883 | } |
||
| 884 | $sql .= ' AND b.bid IN (' . implode(',', $non_grouped) . ')'; |
||
| 885 | $sql .= ' ORDER BY ' . $orderby; |
||
| 886 | $result = $db->query($sql); |
||
| 887 | if (!$db->isResultSet($result)) { |
||
| 888 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 889 | } |
||
| 890 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 891 | $block = new XoopsBlock($myrow); |
||
| 892 | $ret[$myrow['bid']] =& $block; |
||
| 893 | unset($block); |
||
| 894 | } |
||
| 895 | } |
||
| 896 | |||
| 897 | return $ret; |
||
| 898 | } |
||
| 899 | |||
| 900 | /** |
||
| 901 | * XoopsBlock::countSimilarBlocks() |
||
| 902 | * |
||
| 903 | * @param mixed $moduleId |
||
| 904 | * @param mixed $funcNum |
||
| 905 | * @param mixed $showFunc |
||
| 906 | * @return int |
||
| 907 | * |
||
| 908 | * @deprecated |
||
| 909 | */ |
||
| 910 | public function countSimilarBlocks($moduleId, $funcNum, $showFunc = null) |
||
| 933 | } |
||
| 934 | } |
||
| 935 | |||
| 936 | /** |
||
| 937 | * XOOPS block handler class. (Singelton) |
||
| 938 | * |
||
| 1237 |