[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 /** 23 * Class handling all types of 'plugins' (a future term) 24 */ 25 class p_master 26 { 27 var $p_id; 28 var $p_class; 29 var $p_name; 30 var $p_mode; 31 var $p_parent; 32 33 var $include_path = false; 34 var $active_module = false; 35 var $active_module_row_id = false; 36 var $acl_forum_id = false; 37 var $module_ary = array(); 38 39 /** 40 * Constuctor 41 * Set module include path 42 */ 43 function p_master($include_path = false) 44 { 45 global $phpbb_root_path; 46 47 $this->include_path = ($include_path !== false) ? $include_path : $phpbb_root_path . 'includes/'; 48 49 // Make sure the path ends with / 50 if (substr($this->include_path, -1) !== '/') 51 { 52 $this->include_path .= '/'; 53 } 54 } 55 56 /** 57 * Set custom include path for modules 58 * Schema for inclusion is include_path . modulebase 59 * 60 * @param string $include_path include path to be used. 61 * @access public 62 */ 63 function set_custom_include_path($include_path) 64 { 65 $this->include_path = $include_path; 66 67 // Make sure the path ends with / 68 if (substr($this->include_path, -1) !== '/') 69 { 70 $this->include_path .= '/'; 71 } 72 } 73 74 /** 75 * List modules 76 * 77 * This creates a list, stored in $this->module_ary of all available 78 * modules for the given class (ucp, mcp and acp). Additionally 79 * $this->module_y_ary is created with indentation information for 80 * displaying the module list appropriately. Only modules for which 81 * the user has access rights are included in these lists. 82 */ 83 function list_modules($p_class) 84 { 85 global $auth, $db, $user, $cache; 86 global $config, $phpbb_root_path, $phpEx, $phpbb_dispatcher; 87 88 // Sanitise for future path use, it's escaped as appropriate for queries 89 $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); 90 91 // Get cached modules 92 if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false) 93 { 94 // Get modules 95 $sql = 'SELECT * 96 FROM ' . MODULES_TABLE . " 97 WHERE module_class = '" . $db->sql_escape($this->p_class) . "' 98 ORDER BY left_id ASC"; 99 $result = $db->sql_query($sql); 100 101 $rows = array(); 102 while ($row = $db->sql_fetchrow($result)) 103 { 104 $rows[$row['module_id']] = $row; 105 } 106 $db->sql_freeresult($result); 107 108 $this->module_cache = array(); 109 foreach ($rows as $module_id => $row) 110 { 111 $this->module_cache['modules'][] = $row; 112 $this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id'], $rows); 113 } 114 unset($rows); 115 116 $cache->put('_modules_' . $this->p_class, $this->module_cache); 117 } 118 119 if (empty($this->module_cache)) 120 { 121 $this->module_cache = array('modules' => array(), 'parents' => array()); 122 } 123 124 // We "could" build a true tree with this function - maybe mod authors want to use this... 125 // Functions for traversing and manipulating the tree are not available though 126 // We might re-structure the module system to use true trees in 3.2.x... 127 // $tree = $this->build_tree($this->module_cache['modules'], $this->module_cache['parents']); 128 129 // Clean up module cache array to only let survive modules the user can access 130 $right_id = false; 131 132 $hide_categories = array(); 133 foreach ($this->module_cache['modules'] as $key => $row) 134 { 135 // When the module has no mode (category) we check whether it has visible children 136 // before listing it as well. 137 if (!$row['module_mode']) 138 { 139 $hide_categories[(int) $row['module_id']] = $key; 140 } 141 142 // Not allowed to view module? 143 if (!$this->module_auth_self($row['module_auth'])) 144 { 145 unset($this->module_cache['modules'][$key]); 146 continue; 147 } 148 149 // Category with no members, ignore 150 if (!$row['module_basename'] && ($row['left_id'] + 1 == $row['right_id'])) 151 { 152 unset($this->module_cache['modules'][$key]); 153 continue; 154 } 155 156 // Skip branch 157 if ($right_id !== false) 158 { 159 if ($row['left_id'] < $right_id) 160 { 161 unset($this->module_cache['modules'][$key]); 162 continue; 163 } 164 165 $right_id = false; 166 } 167 168 // Not enabled? 169 if (!$row['module_enabled']) 170 { 171 // If category is disabled then disable every child too 172 unset($this->module_cache['modules'][$key]); 173 $right_id = $row['right_id']; 174 continue; 175 } 176 177 if ($row['module_mode']) 178 { 179 // The parent category has a visible child 180 // So remove it and all its parents from the hide array 181 unset($hide_categories[(int) $row['parent_id']]); 182 foreach ($this->module_cache['parents'][$row['module_id']] as $module_id => $row_id) 183 { 184 unset($hide_categories[$module_id]); 185 } 186 } 187 } 188 189 foreach ($hide_categories as $module_id => $row_id) 190 { 191 unset($this->module_cache['modules'][$row_id]); 192 } 193 194 // Re-index (this is needed, else we are not able to array_slice later) 195 $this->module_cache['modules'] = array_merge($this->module_cache['modules']); 196 197 // Include MOD _info files for populating language entries within the menus 198 $this->add_mod_info($this->p_class); 199 200 // Now build the module array, but exclude completely empty categories... 201 $right_id = false; 202 $names = array(); 203 204 foreach ($this->module_cache['modules'] as $key => $row) 205 { 206 // Skip branch 207 if ($right_id !== false) 208 { 209 if ($row['left_id'] < $right_id) 210 { 211 continue; 212 } 213 214 $right_id = false; 215 } 216 217 // Category with no members on their way down (we have to check every level) 218 if (!$row['module_basename']) 219 { 220 $empty_category = true; 221 222 // We go through the branch and look for an activated module 223 foreach (array_slice($this->module_cache['modules'], $key + 1) as $temp_row) 224 { 225 if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id']) 226 { 227 // Module there 228 if ($temp_row['module_basename'] && $temp_row['module_enabled']) 229 { 230 $empty_category = false; 231 break; 232 } 233 continue; 234 } 235 break; 236 } 237 238 // Skip the branch 239 if ($empty_category) 240 { 241 $right_id = $row['right_id']; 242 continue; 243 } 244 } 245 246 $depth = sizeof($this->module_cache['parents'][$row['module_id']]); 247 248 // We need to prefix the functions to not create a naming conflict 249 250 // Function for building 'url_extra' 251 $short_name = $this->get_short_name($row['module_basename']); 252 253 $url_func = 'phpbb_module_' . $short_name . '_url'; 254 if (!function_exists($url_func)) 255 { 256 $url_func = '_module_' . $short_name . '_url'; 257 } 258 259 // Function for building the language name 260 $lang_func = 'phpbb_module_' . $short_name . '_lang'; 261 if (!function_exists($lang_func)) 262 { 263 $lang_func = '_module_' . $short_name . '_lang'; 264 } 265 266 // Custom function for calling parameters on module init (for example assigning template variables) 267 $custom_func = 'phpbb_module_' . $short_name; 268 if (!function_exists($custom_func)) 269 { 270 $custom_func = '_module_' . $short_name; 271 } 272 273 $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; 274 275 $module_row = array( 276 'depth' => $depth, 277 278 'id' => (int) $row['module_id'], 279 'parent' => (int) $row['parent_id'], 280 'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false, 281 282 'is_duplicate' => ($row['module_basename'] && sizeof($names[$row['module_basename'] . '_' . $row['module_mode']]) > 1) ? true : false, 283 284 'name' => (string) $row['module_basename'], 285 'mode' => (string) $row['module_mode'], 286 'display' => (int) $row['module_display'], 287 288 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '', 289 290 'lang' => ($row['module_basename'] && function_exists($lang_func)) ? $lang_func($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']), 291 'langname' => $row['module_langname'], 292 293 'left' => $row['left_id'], 294 'right' => $row['right_id'], 295 ); 296 297 if (function_exists($custom_func)) 298 { 299 $custom_func($row['module_mode'], $module_row); 300 } 301 302 /** 303 * This event allows to modify parameters for building modules list 304 * 305 * @event core.modify_module_row 306 * @var string url_func Function for building 'url_extra' 307 * @var string lang_func Function for building the language name 308 * @var string custom_func Custom function for calling parameters on module init 309 * @var array row Array holding the basic module data 310 * @var array module_row Array holding the module display parameters 311 * @since 3.1.0-b3 312 */ 313 $vars = array('url_func', 'lang_func', 'custom_func', 'row', 'module_row'); 314 extract($phpbb_dispatcher->trigger_event('core.modify_module_row', compact($vars))); 315 316 $this->module_ary[] = $module_row; 317 } 318 319 unset($this->module_cache['modules'], $names); 320 } 321 322 /** 323 * Check if a certain main module is accessible/loaded 324 * By giving the module mode you are able to additionally check for only one mode within the main module 325 * 326 * @param string $module_basename The module base name, for example logs, reports, main (for the mcp). 327 * @param mixed $module_mode The module mode to check. If provided the mode will be checked in addition for presence. 328 * 329 * @return bool Returns true if module is loaded and accessible, else returns false 330 */ 331 function loaded($module_basename, $module_mode = false) 332 { 333 if (!$this->is_full_class($module_basename)) 334 { 335 $module_basename = $this->p_class . '_' . $module_basename; 336 } 337 338 if (empty($this->loaded_cache)) 339 { 340 $this->loaded_cache = array(); 341 342 foreach ($this->module_ary as $row) 343 { 344 if (!$row['name']) 345 { 346 continue; 347 } 348 349 if (!isset($this->loaded_cache[$row['name']])) 350 { 351 $this->loaded_cache[$row['name']] = array(); 352 } 353 354 if (!$row['mode']) 355 { 356 continue; 357 } 358 359 $this->loaded_cache[$row['name']][$row['mode']] = true; 360 } 361 } 362 363 if ($module_mode === false) 364 { 365 return (isset($this->loaded_cache[$module_basename])) ? true : false; 366 } 367 368 return (!empty($this->loaded_cache[$module_basename][$module_mode])) ? true : false; 369 } 370 371 /** 372 * Check module authorisation. 373 * 374 * This is a non-static version that uses $this->acl_forum_id 375 * for the forum id. 376 */ 377 function module_auth_self($module_auth) 378 { 379 return self::module_auth($module_auth, $this->acl_forum_id); 380 } 381 382 /** 383 * Check module authorisation. 384 * 385 * This is a static version, it must be given $forum_id. 386 * See also module_auth_self. 387 */ 388 static function module_auth($module_auth, $forum_id) 389 { 390 global $auth, $config; 391 global $request, $phpbb_extension_manager, $phpbb_dispatcher; 392 393 $module_auth = trim($module_auth); 394 395 // Generally allowed to access module if module_auth is empty 396 if (!$module_auth) 397 { 398 return true; 399 } 400 401 // With the code below we make sure only those elements get eval'd we really want to be checked 402 preg_match_all('/(?: 403 "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | 404 \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | 405 [(),] | 406 [^\s(),]+)/x', $module_auth, $match); 407 408 // Valid tokens for auth and their replacements 409 $valid_tokens = array( 410 'acl_([a-z0-9_]+)(,\$id)?' => '(int) $auth->acl_get(\'\\1\'\\2)', 411 '\$id' => '(int) $forum_id', 412 'aclf_([a-z0-9_]+)' => '(int) $auth->acl_getf_global(\'\\1\')', 413 'cfg_([a-z0-9_]+)' => '(int) $config[\'\\1\']', 414 'request_([a-zA-Z0-9_]+)' => '$request->variable(\'\\1\', false)', 415 'ext_([a-zA-Z0-9_/]+)' => 'array_key_exists(\'\\1\', $phpbb_extension_manager->all_enabled())', 416 'authmethod_([a-z0-9_\\\\]+)' => '($config[\'auth_method\'] === \'\\1\')', 417 ); 418 419 /** 420 * Alter tokens for module authorisation check 421 * 422 * @event core.module_auth 423 * @var array valid_tokens Valid tokens and their auth check 424 * replacements 425 * @var string module_auth The module_auth of the current 426 * module 427 * @var int forum_id The current forum_id 428 * @since 3.1.0-a3 429 */ 430 $vars = array('valid_tokens', 'module_auth', 'forum_id'); 431 extract($phpbb_dispatcher->trigger_event('core.module_auth', compact($vars))); 432 433 $tokens = $match[0]; 434 for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) 435 { 436 $token = &$tokens[$i]; 437 438 switch ($token) 439 { 440 case ')': 441 case '(': 442 case '&&': 443 case '||': 444 case ',': 445 break; 446 447 default: 448 if (!preg_match('#(?:' . implode(array_keys($valid_tokens), ')|(?:') . ')#', $token)) 449 { 450 $token = ''; 451 } 452 break; 453 } 454 } 455 456 $module_auth = implode(' ', $tokens); 457 458 // Make sure $id separation is working fine 459 $module_auth = str_replace(' , ', ',', $module_auth); 460 461 $module_auth = preg_replace( 462 // Array keys with # prepended/appended 463 array_map(function($value) { 464 return '#' . $value . '#'; 465 }, array_keys($valid_tokens)), 466 array_values($valid_tokens), 467 $module_auth 468 ); 469 470 $is_auth = false; 471 // @codingStandardsIgnoreStart 472 eval('$is_auth = (int) (' . $module_auth . ');'); 473 // @codingStandardsIgnoreEnd 474 475 return $is_auth; 476 } 477 478 /** 479 * Set active module 480 */ 481 function set_active($id = false, $mode = false) 482 { 483 $icat = false; 484 $this->active_module = false; 485 486 if (request_var('icat', '')) 487 { 488 $icat = $id; 489 $id = request_var('icat', ''); 490 } 491 492 // Restore the backslashes in class names 493 if (strpos($id, '-') !== false) 494 { 495 $id = str_replace('-', '\\', $id); 496 } 497 498 if ($id && !is_numeric($id) && !$this->is_full_class($id)) 499 { 500 $id = $this->p_class . '_' . $id; 501 } 502 503 $category = false; 504 foreach ($this->module_ary as $row_id => $item_ary) 505 { 506 // If this is a module and it's selected, active 507 // If this is a category and the module is the first within it, active 508 // If this is a module and no mode selected, select first mode 509 // If no category or module selected, go active for first module in first category 510 if ( 511 (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || 512 ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) || 513 (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || 514 (!$id && !$mode && !$item_ary['cat'] && $item_ary['display']) 515 ) 516 { 517 if ($item_ary['cat']) 518 { 519 $id = $icat; 520 $icat = false; 521 522 continue; 523 } 524 525 $this->p_id = $item_ary['id']; 526 $this->p_parent = $item_ary['parent']; 527 $this->p_name = $item_ary['name']; 528 $this->p_mode = $item_ary['mode']; 529 $this->p_left = $item_ary['left']; 530 $this->p_right = $item_ary['right']; 531 532 $this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id]; 533 $this->active_module = $item_ary['id']; 534 $this->active_module_row_id = $row_id; 535 536 break; 537 } 538 else if (($item_ary['cat'] && $item_ary['id'] === (int) $id) || ($item_ary['parent'] === $category && $item_ary['cat'])) 539 { 540 $category = $item_ary['id']; 541 } 542 } 543 } 544 545 /** 546 * Loads currently active module 547 * 548 * This method loads a given module, passing it the relevant id and mode. 549 * 550 * @param string|false $mode mode, as passed through to the module 551 * @param string|false $module_url If supplied, we use this module url 552 * @param bool $execute_module If true, at the end we execute the main method for the new instance 553 */ 554 function load_active($mode = false, $module_url = false, $execute_module = true) 555 { 556 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $template; 557 558 $module_path = $this->include_path . $this->p_class; 559 $icat = request_var('icat', ''); 560 561 if ($this->active_module === false) 562 { 563 trigger_error('MODULE_NOT_ACCESS', E_USER_ERROR); 564 } 565 566 // new modules use the full class names, old ones are always called <type>_<name>, e.g. acp_board 567 if (!class_exists($this->p_name)) 568 { 569 if (!file_exists("$module_path/{$this->p_name}.$phpEx")) 570 { 571 trigger_error($user->lang('MODULE_NOT_FIND', "$module_path/{$this->p_name}.$phpEx"), E_USER_ERROR); 572 } 573 574 include("$module_path/{$this->p_name}.$phpEx"); 575 576 if (!class_exists($this->p_name)) 577 { 578 trigger_error($user->lang('MODULE_FILE_INCORRECT_CLASS', "$module_path/{$this->p_name}.$phpEx", $this->p_name), E_USER_ERROR); 579 } 580 } 581 582 if (!empty($mode)) 583 { 584 $this->p_mode = $mode; 585 } 586 587 // Create a new instance of the desired module ... 588 $class_name = $this->p_name; 589 590 $this->module = new $class_name($this); 591 592 // We pre-define the action parameter we are using all over the place 593 if (defined('IN_ADMIN')) 594 { 595 /* 596 * If this is an extension module, we'll try to automatically set 597 * the style paths for the extension (the ext author can change them 598 * if necessary). 599 */ 600 $module_dir = explode('\\', get_class($this->module)); 601 602 // 0 vendor, 1 extension name, ... 603 if (isset($module_dir[1])) 604 { 605 $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/adm/style'; 606 607 if (is_dir($module_style_dir)) 608 { 609 $template->set_custom_style(array( 610 array( 611 'name' => 'adm', 612 'ext_path' => 'adm/style/', 613 ), 614 ), array($module_style_dir, $phpbb_admin_path . 'style')); 615 } 616 } 617 618 // Is first module automatically enabled a duplicate and the category not passed yet? 619 if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) 620 { 621 $icat = $this->module_ary[$this->active_module_row_id]['parent']; 622 } 623 624 // Not being able to overwrite ;) 625 $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=' . $this->get_module_identifier($this->p_name)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; 626 } 627 else 628 { 629 /* 630 * If this is an extension module, we'll try to automatically set 631 * the style paths for the extension (the ext author can change them 632 * if necessary). 633 */ 634 $module_dir = explode('\\', get_class($this->module)); 635 636 // 0 vendor, 1 extension name, ... 637 if (isset($module_dir[1])) 638 { 639 $module_style_dir = 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/styles'; 640 641 if (is_dir($phpbb_root_path . $module_style_dir)) 642 { 643 $template->set_style(array($module_style_dir, 'styles')); 644 } 645 } 646 647 // If user specified the module url we will use it... 648 if ($module_url !== false) 649 { 650 $this->module->u_action = $module_url; 651 } 652 else 653 { 654 $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; 655 } 656 657 $this->module->u_action = append_sid($this->module->u_action, 'i=' . $this->get_module_identifier($this->p_name)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; 658 } 659 660 // Add url_extra parameter to u_action url 661 if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) 662 { 663 $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; 664 } 665 666 // Assign the module path for re-usage 667 $this->module->module_path = $module_path . '/'; 668 669 // Execute the main method for the new instance, we send the module id and mode as parameters 670 // Users are able to call the main method after this function to be able to assign additional parameters manually 671 if ($execute_module) 672 { 673 $short_name = preg_replace("#^{$this->p_class}_#", '', $this->p_name); 674 $this->module->main($short_name, $this->p_mode); 675 } 676 } 677 678 /** 679 * Appending url parameter to the currently active module. 680 * 681 * This function is called for adding specific url parameters while executing the current module. 682 * It is doing the same as the _module_{name}_url() function, apart from being able to be called after 683 * having dynamically parsed specific parameters. This allows more freedom in choosing additional parameters. 684 * One example can be seen in /includes/mcp/mcp_notes.php - $this->p_master->adjust_url() call. 685 * 686 * @param string $url_extra Extra url parameters, e.g.: &u=$user_id 687 * 688 */ 689 function adjust_url($url_extra) 690 { 691 if (empty($this->module_ary[$this->active_module_row_id])) 692 { 693 return; 694 } 695 696 $row = &$this->module_ary[$this->active_module_row_id]; 697 698 // We check for the same url_extra in $row['url_extra'] to overcome doubled additions... 699 if (strpos($row['url_extra'], $url_extra) === false) 700 { 701 $row['url_extra'] .= $url_extra; 702 } 703 } 704 705 /** 706 * Check if a module is active 707 */ 708 function is_active($id, $mode = false) 709 { 710 // If we find a name by this id and being enabled we have our active one... 711 foreach ($this->module_ary as $row_id => $item_ary) 712 { 713 if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display'] || $item_ary['name'] === $this->p_class . '_' . $id) 714 { 715 if ($mode === false || $mode === $item_ary['mode']) 716 { 717 return true; 718 } 719 } 720 } 721 722 return false; 723 } 724 725 /** 726 * Get parents 727 */ 728 function get_parents($parent_id, $left_id, $right_id, &$all_parents) 729 { 730 global $db; 731 732 $parents = array(); 733 734 if ($parent_id > 0) 735 { 736 foreach ($all_parents as $module_id => $row) 737 { 738 if ($row['left_id'] < $left_id && $row['right_id'] > $right_id) 739 { 740 $parents[$module_id] = $row['parent_id']; 741 } 742 743 if ($row['left_id'] > $left_id) 744 { 745 break; 746 } 747 } 748 } 749 750 return $parents; 751 } 752 753 /** 754 * Get tree branch 755 */ 756 function get_branch($left_id, $right_id, $remaining) 757 { 758 $branch = array(); 759 760 foreach ($remaining as $key => $row) 761 { 762 if ($row['left_id'] > $left_id && $row['left_id'] < $right_id) 763 { 764 $branch[] = $row; 765 continue; 766 } 767 break; 768 } 769 770 return $branch; 771 } 772 773 /** 774 * Build true binary tree from given array 775 * Not in use 776 */ 777 function build_tree(&$modules, &$parents) 778 { 779 $tree = array(); 780 781 foreach ($modules as $row) 782 { 783 $branch = &$tree; 784 785 if ($row['parent_id']) 786 { 787 // Go through the tree to find our branch 788 $parent_tree = $parents[$row['module_id']]; 789 790 foreach ($parent_tree as $id => $value) 791 { 792 if (!isset($branch[$id]) && isset($branch['child'])) 793 { 794 $branch = &$branch['child']; 795 } 796 $branch = &$branch[$id]; 797 } 798 $branch = &$branch['child']; 799 } 800 801 $branch[$row['module_id']] = $row; 802 if (!isset($branch[$row['module_id']]['child'])) 803 { 804 $branch[$row['module_id']]['child'] = array(); 805 } 806 } 807 808 return $tree; 809 } 810 811 /** 812 * Build navigation structure 813 */ 814 function assign_tpl_vars($module_url) 815 { 816 global $template; 817 818 $current_id = $right_id = false; 819 820 // Make sure the module_url has a question mark set, effectively determining the delimiter to use 821 $delim = (strpos($module_url, '?') === false) ? '?' : '&'; 822 823 $current_padding = $current_depth = 0; 824 $linear_offset = 'l_block1'; 825 $tabular_offset = 't_block2'; 826 827 // Generate the list of modules, we'll do this in two ways ... 828 // 1) In a linear fashion 829 // 2) In a combined tabbed + linear fashion ... tabs for the categories 830 // and a linear list for subcategories/items 831 foreach ($this->module_ary as $row_id => $item_ary) 832 { 833 // Skip hidden modules 834 if (!$item_ary['display']) 835 { 836 continue; 837 } 838 839 // Skip branch 840 if ($right_id !== false) 841 { 842 if ($item_ary['left'] < $right_id) 843 { 844 continue; 845 } 846 847 $right_id = false; 848 } 849 850 // Category with no members on their way down (we have to check every level) 851 if (!$item_ary['name']) 852 { 853 $empty_category = true; 854 855 // We go through the branch and look for an activated module 856 foreach (array_slice($this->module_ary, $row_id + 1) as $temp_row) 857 { 858 if ($temp_row['left'] > $item_ary['left'] && $temp_row['left'] < $item_ary['right']) 859 { 860 // Module there and displayed? 861 if ($temp_row['name'] && $temp_row['display']) 862 { 863 $empty_category = false; 864 break; 865 } 866 continue; 867 } 868 break; 869 } 870 871 // Skip the branch 872 if ($empty_category) 873 { 874 $right_id = $item_ary['right']; 875 continue; 876 } 877 } 878 879 // Select first id we can get 880 if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id)) 881 { 882 $current_id = $item_ary['id']; 883 } 884 885 $depth = $item_ary['depth']; 886 887 if ($depth > $current_depth) 888 { 889 $linear_offset = $linear_offset . '.l_block' . ($depth + 1); 890 $tabular_offset = ($depth + 1 > 2) ? $tabular_offset . '.t_block' . ($depth + 1) : $tabular_offset; 891 } 892 else if ($depth < $current_depth) 893 { 894 for ($i = $current_depth - $depth; $i > 0; $i--) 895 { 896 $linear_offset = substr($linear_offset, 0, strrpos($linear_offset, '.')); 897 $tabular_offset = ($i + $depth > 1) ? substr($tabular_offset, 0, strrpos($tabular_offset, '.')) : $tabular_offset; 898 } 899 } 900 901 $u_title = $module_url . $delim . 'i='; 902 // if the item has a name use it, else use its id 903 if (empty($item_ary['name'])) 904 { 905 $u_title .= $item_ary['id']; 906 } 907 else 908 { 909 // if the category has a name, then use it. 910 $u_title .= $this->get_module_identifier($item_ary['name']); 911 } 912 // If the item is not a category append the mode 913 if (!$item_ary['cat']) 914 { 915 if ($item_ary['is_duplicate']) 916 { 917 $u_title .= '&icat=' . $current_id; 918 } 919 $u_title .= '&mode=' . $item_ary['mode']; 920 } 921 922 // Was not allowed in categories before - /*!$item_ary['cat'] && */ 923 $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; 924 925 // Only output a categories items if it's currently selected 926 if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent))) 927 { 928 $use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset; 929 930 $tpl_ary = array( 931 'L_TITLE' => $item_ary['lang'], 932 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, 933 'U_TITLE' => $u_title 934 ); 935 936 $template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); 937 } 938 939 $tpl_ary = array( 940 'L_TITLE' => $item_ary['lang'], 941 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, 942 'U_TITLE' => $u_title 943 ); 944 945 $template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); 946 947 $current_depth = $depth; 948 } 949 } 950 951 /** 952 * Returns desired template name 953 */ 954 function get_tpl_name() 955 { 956 return $this->module->tpl_name . '.html'; 957 } 958 959 /** 960 * Returns the desired page title 961 */ 962 function get_page_title() 963 { 964 global $user; 965 966 if (!isset($this->module->page_title)) 967 { 968 return ''; 969 } 970 971 return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title; 972 } 973 974 /** 975 * Load module as the current active one without the need for registering it 976 * 977 * @param string $class module class (acp/mcp/ucp) 978 * @param string $name module name (class name of the module, or its basename 979 * phpbb_ext_foo_acp_bar_module, ucp_zebra or zebra) 980 * @param string $mode mode, as passed through to the module 981 * 982 */ 983 function load($class, $name, $mode = false) 984 { 985 // new modules use the full class names, old ones are always called <class>_<name>, e.g. acp_board 986 // in the latter case this function may be called as load('acp', 'board') 987 if (!class_exists($name) && substr($name, 0, strlen($class) + 1) !== $class . '_') 988 { 989 $name = $class . '_' . $name; 990 } 991 992 $this->p_class = $class; 993 $this->p_name = $name; 994 995 // Set active module to true instead of using the id 996 $this->active_module = true; 997 998 $this->load_active($mode); 999 } 1000 1001 /** 1002 * Display module 1003 */ 1004 function display($page_title, $display_online_list = false) 1005 { 1006 global $template, $user; 1007 1008 // Generate the page 1009 if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) 1010 { 1011 adm_page_header($page_title); 1012 } 1013 else 1014 { 1015 page_header($page_title, $display_online_list); 1016 } 1017 1018 $template->set_filenames(array( 1019 'body' => $this->get_tpl_name()) 1020 ); 1021 1022 if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) 1023 { 1024 adm_page_footer(); 1025 } 1026 else 1027 { 1028 page_footer(); 1029 } 1030 } 1031 1032 /** 1033 * Toggle whether this module will be displayed or not 1034 */ 1035 function set_display($id, $mode = false, $display = true) 1036 { 1037 foreach ($this->module_ary as $row_id => $item_ary) 1038 { 1039 if (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) 1040 { 1041 $this->module_ary[$row_id]['display'] = (int) $display; 1042 } 1043 } 1044 } 1045 1046 /** 1047 * Add custom MOD info language file 1048 */ 1049 function add_mod_info($module_class) 1050 { 1051 global $config, $user, $phpEx, $phpbb_extension_manager; 1052 1053 $finder = $phpbb_extension_manager->get_finder(); 1054 1055 // We grab the language files from the default, English and user's language. 1056 // So we can fall back to the other files like we do when using add_lang() 1057 $default_lang_files = $english_lang_files = $user_lang_files = array(); 1058 1059 // Search for board default language if it's not the user language 1060 if ($config['default_lang'] != $user->lang_name) 1061 { 1062 $default_lang_files = $finder 1063 ->prefix('info_' . strtolower($module_class) . '_') 1064 ->suffix(".$phpEx") 1065 ->extension_directory('/language/' . basename($config['default_lang'])) 1066 ->core_path('language/' . basename($config['default_lang']) . '/mods/') 1067 ->find(); 1068 } 1069 1070 // Search for english, if its not the default or user language 1071 if ($config['default_lang'] != 'en' && $user->lang_name != 'en') 1072 { 1073 $english_lang_files = $finder 1074 ->prefix('info_' . strtolower($module_class) . '_') 1075 ->suffix(".$phpEx") 1076 ->extension_directory('/language/en') 1077 ->core_path('language/en/mods/') 1078 ->find(); 1079 } 1080 1081 // Find files in the user's language 1082 $user_lang_files = $finder 1083 ->prefix('info_' . strtolower($module_class) . '_') 1084 ->suffix(".$phpEx") 1085 ->extension_directory('/language/' . $user->lang_name) 1086 ->core_path('language/' . $user->lang_name . '/mods/') 1087 ->find(); 1088 1089 $lang_files = array_merge($english_lang_files, $default_lang_files, $user_lang_files); 1090 foreach ($lang_files as $lang_file => $ext_name) 1091 { 1092 $user->add_lang_ext($ext_name, $lang_file); 1093 } 1094 } 1095 1096 /** 1097 * Retrieve shortened module basename for legacy basenames (with xcp_ prefix) 1098 * 1099 * @param string $basename A module basename 1100 * @return string The basename if it starts with phpbb_ or the basename with 1101 * the current p_class (e.g. acp_) stripped. 1102 */ 1103 protected function get_short_name($basename) 1104 { 1105 if (substr($basename, 0, 6) === 'phpbb\\' || strpos($basename, '\\') !== false) 1106 { 1107 return $basename; 1108 } 1109 1110 // strip xcp_ prefix from old classes 1111 return substr($basename, strlen($this->p_class) + 1); 1112 } 1113 1114 /** 1115 * If the basename contains a \ we don't use that for the URL. 1116 * 1117 * Firefox is currently unable to correctly copy a urlencoded \ 1118 * so users will be unable to post links to modules. 1119 * However we can replace them with dashes and re-replace them later 1120 * 1121 * @param string $basename Basename of the module 1122 * @return string Identifier that should be used for 1123 * module link creation 1124 */ 1125 protected function get_module_identifier($basename) 1126 { 1127 if (strpos($basename, '\\') === false) 1128 { 1129 return $basename; 1130 } 1131 1132 return str_replace('\\', '-', $basename); 1133 } 1134 1135 /** 1136 * Checks whether the given module basename is a correct class name 1137 * 1138 * @param string $basename A module basename 1139 * @return bool True if the basename starts with phpbb_ or (x)cp_, false otherwise 1140 */ 1141 protected function is_full_class($basename) 1142 { 1143 return (strpos($basename, '\\') !== false || preg_match('/^(ucp|mcp|acp)_/', $basename)); 1144 } 1145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |