From 4844b007771f71973db2fa440d3c8ef9057d1b02 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 22 Aug 2011 03:19:17 -0400 Subject: [feature/extension-manager] Load (A/U/M)CP modules from extensions To avoid large bc breaking changes, modules in the old includes directory structure still follow the same naming conventions. Modules in extensions have to be placed in an xcp/ folder and need a _module suffix. The corresponding info file is in the same directory but with an _info suffix. PHPBB3-10323 --- phpBB/includes/functions_module.php | 84 ++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 43 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 09c54422b0..1a6b57794a 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -440,7 +440,8 @@ 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 _, e.g. acp_board + if (!class_exists($this->p_name) && !class_exists("{$this->p_class}_$this->p_name")) { if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) { @@ -453,62 +454,59 @@ class p_master { 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); } + } - 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 = (class_exists($this->p_name)) ? $this->p_name : "{$this->p_class}_$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) + { + $this->module->main($this->p_name, $this->p_mode); } } -- cgit v1.2.1 From fe4b8818ec1f448d5625534e5027cfbc1177ab9a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 20:54:42 -0400 Subject: [feature/extension-manager] Always store the full class name as module basename The updater swaps out all basenames. PHPBB3-10323 --- phpBB/includes/functions_module.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 1a6b57794a..4d575a7e3a 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -441,18 +441,19 @@ class p_master } // new modules use the full class names, old ones are always called _, e.g. acp_board - if (!class_exists($this->p_name) && !class_exists("{$this->p_class}_$this->p_name")) + 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); } } @@ -462,7 +463,7 @@ class p_master } // Create a new instance of the desired module ... - $class_name = (class_exists($this->p_name)) ? $this->p_name : "{$this->p_class}_$this->p_name"; + $class_name = $this->p_name; $this->module = new $class_name($this); -- cgit v1.2.1 From 7b12bba95bb7c59bde65e8ea1ffb1275944fd965 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 13 Oct 2011 17:38:38 +0200 Subject: [feature/extension-manager] Allow old non-prefix basenames to work for lookups These module basenames are hardcoded in a bunch of places so they need to continue to work unless we want to rewrite all of them. PHPBB3-10323 --- phpBB/includes/functions_module.php | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 4d575a7e3a..9226a75d4c 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(); @@ -381,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) { @@ -389,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']) ) { @@ -445,7 +457,6 @@ class p_master { if (!file_exists("$module_path/{$this->p_name}.$phpEx")) { - trigger_error("Cannot find module $module_path/{$this->p_name}.$phpEx", E_USER_ERROR); } @@ -507,7 +518,8 @@ class p_master // 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); + $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; } @@ -878,4 +890,20 @@ class p_master } } } + + 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); + } + + function is_full_class($basename) + { + return (substr($basename, 0, 6) === 'phpbb_' || substr($basename, 0, strlen($this->p_class) + 1) === $this->p_class . '_'); + } } -- cgit v1.2.1 From 639e3b9f17c9bac668b4ad24bb9861d8006fa396 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2011 00:44:48 +0200 Subject: [feature/extension-manager] Support for loading language files from extensions The referenced extension needs to be explicitly specified in an add_lang_ext() call. PHPBB3-10323 --- phpBB/includes/functions_module.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 9226a75d4c..946e7d2b8d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -865,7 +865,7 @@ class p_master function add_mod_info($module_class) { global $user, $phpEx; - +/* if (file_exists($user->lang_path . $user->lang_name . '/mods')) { $add_files = array(); @@ -888,6 +888,23 @@ class p_master { $user->add_lang($add_files); } + }*/ + + global $phpbb_extension_manager; + + $finder = $phpbb_extension_manager->get_finder(); + + $lang_files = $finder + ->prefix('info_' . strtolower($module_class) . '_') + ->suffix(".$phpEx") + ->directory('/language/' . $user->lang_name) + ->default_path('language/' . $user->lang_name . '/mods/') + ->default_directory('') + ->find(); + + foreach ($lang_files as $lang_file => $ext_name) + { + $user->add_lang_ext($ext_name, $lang_file); } } -- cgit v1.2.1 From cd522a11f3f40e0429bebb7bd7cfee1b442a83ef Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2011 01:31:24 +0200 Subject: [feature/extension-manager] Properly remove old ACP language loading code PHPBB3-10323 --- phpBB/includes/functions_module.php | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 946e7d2b8d..e2b2d80b3e 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -865,30 +865,6 @@ class p_master function add_mod_info($module_class) { global $user, $phpEx; -/* - if (file_exists($user->lang_path . $user->lang_name . '/mods')) - { - $add_files = array(); - - $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); - - 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); - } - - if (sizeof($add_files)) - { - $user->add_lang($add_files); - } - }*/ global $phpbb_extension_manager; -- cgit v1.2.1 From 81ac3698089ce86c1e8a44bafacf881d6d8def4a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 14:43:38 +0100 Subject: [feature/extension-manager] Add docblocks to new methods in functions_module PHPBB3-10323 --- phpBB/includes/functions_module.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index e2b2d80b3e..ce49c3a798 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -884,7 +884,14 @@ class p_master } } - function get_short_name($basename) + /** + * 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_') { @@ -895,7 +902,13 @@ class p_master return substr($basename, strlen($this->p_class) + 1); } - function is_full_class($basename) + /** + * 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 . '_'); } -- cgit v1.2.1 From 0d296785b2364f894f34171d054341cc4979223f Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 16:42:53 +0100 Subject: [feature/extension-manager] Rename default methods to core methods on finder. There are now extension_ and core_ methods for all finder settings as well as a generic method which overwrites both. PHPBB3-10323 --- phpBB/includes/functions_module.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ce49c3a798..1f451d392d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -873,9 +873,8 @@ class p_master $lang_files = $finder ->prefix('info_' . strtolower($module_class) . '_') ->suffix(".$phpEx") - ->directory('/language/' . $user->lang_name) - ->default_path('language/' . $user->lang_name . '/mods/') - ->default_directory('') + ->extension_directory('/language/' . $user->lang_name) + ->core_path('language/' . $user->lang_name . '/mods/') ->find(); foreach ($lang_files as $lang_file => $ext_name) -- cgit v1.2.1 From 7a04c9048c110f0bd21ea3e9e869e17b408d640e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 31 Dec 2011 13:32:52 +0000 Subject: [ticket/9916] Updating header license and removing Version $Id$ PHPBB3-9916 --- phpBB/includes/functions_module.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 1f451d392d..d810285313 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -2,9 +2,8 @@ /** * * @package phpBB3 -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From ffde8c8e06c4d37bef5cde280d520c0791ed2c67 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 6 Jan 2012 17:20:41 +0100 Subject: [ticket/10477] Normalize loaded module names to be class names or xcp_ prefixed PHPBB3-10477 --- phpBB/includes/functions_module.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index d810285313..a6015b1eac 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -804,6 +804,13 @@ class p_master */ function load($class, $name, $mode = false) { + // new modules use the full class names, old ones are always called _, e.g. acp_board + // in the latter case this function may be called as load(acp, board) + if (!class_exists($name) && substr($name, 0, strlen($class) + 1) !== $class . '_') + { + $name = $class . '_' . $name; + } + $this->p_class = $class; $this->p_name = $name; -- cgit v1.2.1 From 3f754d118d8fbd36dcefbeea470ecb267e87ace6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 12 Jan 2012 22:13:28 -0500 Subject: [ticket/10477] Document parameters to p_master#load. PHPBB3-10477 --- phpBB/includes/functions_module.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index a6015b1eac..653623a336 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -438,6 +438,8 @@ class p_master * Loads currently active module * * This method loads a given module, passing it the relevant id and mode. + * + * @param string $mode mode, as passed through to the module */ function load_active($mode = false, $module_url = false, $execute_module = true) { @@ -801,11 +803,16 @@ class p_master /** * Load module as the current active one without the need for registering it + * + * @param string $class module class (acp/mcp/ucp) + * @param string $name module name (e.g. zebra for the ucp_zebra module) + * @param string $mode mode, as passed through to the module + * */ function load($class, $name, $mode = false) { // new modules use the full class names, old ones are always called _, e.g. acp_board - // in the latter case this function may be called as load(acp, board) + // in the latter case this function may be called as load('acp', 'board') if (!class_exists($name) && substr($name, 0, strlen($class) + 1) !== $class . '_') { $name = $class . '_' . $name; -- cgit v1.2.1 From 82c05a7ed6cde2ce1a217b988382167aa94fcf03 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 13 Jan 2012 12:59:29 +0100 Subject: [ticket/10477] Correctly document module (base)name parameter PHPBB3-10477 --- phpBB/includes/functions_module.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 653623a336..b7bb770031 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -805,7 +805,8 @@ class p_master * Load module as the current active one without the need for registering it * * @param string $class module class (acp/mcp/ucp) - * @param string $name module name (e.g. zebra for the ucp_zebra module) + * @param string $name module name (class name of the module, or its basename + * phpbb_ext_foo_acp_bar_module, ucp_zebra or zebra) * @param string $mode mode, as passed through to the module * */ -- cgit v1.2.1 From 6cf7f205903767bf44d1ee1de796d5f3a00774cd Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 9 Feb 2012 01:34:37 +0200 Subject: [ticket/10634] Changing p_master::is_full_class Changing p_master::is_full_class to check allow all module types, not only current type PHPBB3-10634 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index b7bb770031..db7defdc48 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -923,6 +923,6 @@ class p_master */ protected function is_full_class($basename) { - return (substr($basename, 0, 6) === 'phpbb_' || substr($basename, 0, strlen($this->p_class) + 1) === $this->p_class . '_'); + return (preg_match('/^(phpbb|ucp|mcp|acp)_/', $basename)); } } -- cgit v1.2.1