| Total Complexity | 115 |
| Total Lines | 842 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| 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 | /** |
||
| 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() |
||
| 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) |
||
| 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(); |
||
| 1174 |