diff options
Diffstat (limited to 'phpBB/includes/functions_module.php')
-rw-r--r-- | phpBB/includes/functions_module.php | 185 |
1 files changed, 108 insertions, 77 deletions
diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index d0e7c8cfc8..1f451d392d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -221,13 +221,15 @@ class p_master // We need to prefix the functions to not create a naming conflict // Function for building 'url_extra' - $url_func = '_module_' . $row['module_basename'] . '_url'; + $short_name = $this->get_short_name($row['module_basename']); + + $url_func = '_module_' . $short_name . '_url'; // Function for building the language name - $lang_func = '_module_' . $row['module_basename'] . '_lang'; + $lang_func = '_module_' . $short_name . '_lang'; // Custom function for calling parameters on module init (for example assigning template variables) - $custom_func = '_module_' . $row['module_basename']; + $custom_func = '_module_' . $short_name; $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; @@ -275,6 +277,11 @@ class p_master */ function loaded($module_basename, $module_mode = false) { + if (!$this->is_full_class($module_basename)) + { + $module_basename = $this->p_class . '_' . $module_basename; + } + if (empty($this->loaded_cache)) { $this->loaded_cache = array(); @@ -314,6 +321,7 @@ class p_master function module_auth($module_auth, $forum_id = false) { global $auth, $config; + global $request; $module_auth = trim($module_auth); @@ -361,7 +369,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z0-9_]+)(,\$id)?#', '#\$id#', '#aclf_([a-z0-9_]+)#', '#cfg_([a-z0-9_]+)#', '#request_([a-zA-Z0-9_]+)#'), array('(int) $auth->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) $auth->acl_getf_global(\'\\1\')', '(int) $config[\'\\1\']', '!empty($_REQUEST[\'\\1\'])'), $module_auth) . ');'); + eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z0-9_]+)(,\$id)?#', '#\$id#', '#aclf_([a-z0-9_]+)#', '#cfg_([a-z0-9_]+)#', '#request_([a-zA-Z0-9_]+)#'), array('(int) $auth->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) $auth->acl_getf_global(\'\\1\')', '(int) $config[\'\\1\']', '$request->variable(\'\\1\', false)'), $module_auth) . ');'); return $is_auth; } @@ -380,6 +388,11 @@ class p_master $id = request_var('icat', ''); } + if ($id && !is_numeric($id) && !$this->is_full_class($id)) + { + $id = $this->p_class . '_' . $id; + } + $category = false; foreach ($this->module_ary as $row_id => $item_ary) { @@ -388,9 +401,9 @@ class p_master // If this is a module and no mode selected, select first mode // If no category or module selected, go active for first module in first category if ( - (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || + (($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']))) || ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) || - (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || + (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || (!$id && !$mode && !$item_ary['cat'] && $item_ary['display']) ) { @@ -439,75 +452,74 @@ class p_master trigger_error('Module not accessible', E_USER_ERROR); } - if (!class_exists("{$this->p_class}_$this->p_name")) + // new modules use the full class names, old ones are always called <type>_<name>, e.g. acp_board + if (!class_exists($this->p_name)) { - if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) + if (!file_exists("$module_path/{$this->p_name}.$phpEx")) { - trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR); + trigger_error("Cannot find module $module_path/{$this->p_name}.$phpEx", E_USER_ERROR); } - include("$module_path/{$this->p_class}_$this->p_name.$phpEx"); + include("$module_path/{$this->p_name}.$phpEx"); - if (!class_exists("{$this->p_class}_$this->p_name")) + if (!class_exists($this->p_name)) { - trigger_error("Module file $module_path/{$this->p_class}_$this->p_name.$phpEx does not contain correct class [{$this->p_class}_$this->p_name]", E_USER_ERROR); + trigger_error("Module file $module_path/{$this->p_name}.$phpEx does not contain correct class [{$this->p_name}]", E_USER_ERROR); } + } - if (!empty($mode)) - { - $this->p_mode = $mode; - } + if (!empty($mode)) + { + $this->p_mode = $mode; + } - // Create a new instance of the desired module ... if it has a - // constructor it will of course be executed - $instance = "{$this->p_class}_$this->p_name"; + // Create a new instance of the desired module ... + $class_name = $this->p_name; - $this->module = new $instance($this); + $this->module = new $class_name($this); - // We pre-define the action parameter we are using all over the place - if (defined('IN_ADMIN')) + // We pre-define the action parameter we are using all over the place + if (defined('IN_ADMIN')) + { + // Is first module automatically enabled a duplicate and the category not passed yet? + if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) { - // Is first module automatically enabled a duplicate and the category not passed yet? - if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) - { - $icat = $this->module_ary[$this->active_module_row_id]['parent']; - } + $icat = $this->module_ary[$this->active_module_row_id]['parent']; + } - // Not being able to overwrite ;) - $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + // Not being able to overwrite ;) + $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + } + else + { + // If user specified the module url we will use it... + if ($module_url !== false) + { + $this->module->u_action = $module_url; } else { - // If user specified the module url we will use it... - if ($module_url !== false) - { - $this->module->u_action = $module_url; - } - else - { - $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; - } - - $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; } - // Add url_extra parameter to u_action url - if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) - { - $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; - } + $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + } - // Assign the module path for re-usage - $this->module->module_path = $module_path . '/'; + // Add url_extra parameter to u_action url + if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) + { + $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; + } - // Execute the main method for the new instance, we send the module id and mode as parameters - // Users are able to call the main method after this function to be able to assign additional parameters manually - if ($execute_module) - { - $this->module->main($this->p_name, $this->p_mode); - } + // Assign the module path for re-usage + $this->module->module_path = $module_path . '/'; - return; + // Execute the main method for the new instance, we send the module id and mode as parameters + // Users are able to call the main method after this function to be able to assign additional parameters manually + if ($execute_module) + { + $short_name = preg_replace("#^{$this->p_class}_#", '', $this->p_name); + $this->module->main($short_name, $this->p_mode); } } @@ -546,7 +558,7 @@ class p_master // If we find a name by this id and being enabled we have our active one... foreach ($this->module_ary as $row_id => $item_ary) { - if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display']) + if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display'] || $item_ary['name'] === $this->p_class . '_' . $id) { if ($mode === false || $mode === $item_ary['mode']) { @@ -840,7 +852,7 @@ class p_master { foreach ($this->module_ary as $row_id => $item_ary) { - if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) + if (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) { $this->module_ary[$row_id]['display'] = (int) $display; } @@ -854,30 +866,49 @@ class p_master { global $user, $phpEx; - if (file_exists($user->lang_path . $user->lang_name . '/mods')) - { - $add_files = array(); + global $phpbb_extension_manager; - $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); + $finder = $phpbb_extension_manager->get_finder(); - if ($dir) - { - while (($entry = readdir($dir)) !== false) - { - if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx) - { - $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1)); - } - } - closedir($dir); - } + $lang_files = $finder + ->prefix('info_' . strtolower($module_class) . '_') + ->suffix(".$phpEx") + ->extension_directory('/language/' . $user->lang_name) + ->core_path('language/' . $user->lang_name . '/mods/') + ->find(); - if (sizeof($add_files)) - { - $user->add_lang($add_files); - } + foreach ($lang_files as $lang_file => $ext_name) + { + $user->add_lang_ext($ext_name, $lang_file); } } -} -?>
\ No newline at end of file + /** + * Retrieve shortened module basename for legacy basenames (with xcp_ prefix) + * + * @param string $basename A module basename + * @return string The basename if it starts with phpbb_ or the basename with + * the current p_class (e.g. acp_) stripped. + */ + protected function get_short_name($basename) + { + if (substr($basename, 0, 6) === 'phpbb_') + { + return $basename; + } + + // strip xcp_ prefix from old classes + return substr($basename, strlen($this->p_class) + 1); + } + + /** + * Checks whether the given module basename is a correct class name + * + * @param string $basename A module basename + * @return bool True if the basename starts with phpbb_ or (x)cp_, false otherwise + */ + protected function is_full_class($basename) + { + return (substr($basename, 0, 6) === 'phpbb_' || substr($basename, 0, strlen($this->p_class) + 1) === $this->p_class . '_'); + } +} |