diff options
author | Nils Adermann <naderman@naderman.de> | 2011-08-22 03:19:17 -0400 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2011-09-29 15:42:47 +0200 |
commit | 4844b007771f71973db2fa440d3c8ef9057d1b02 (patch) | |
tree | b7cc57543c8a684342f551207b02eebfed9ef2f3 /phpBB/includes/acp/acp_modules.php | |
parent | f6632fcfd08650f13560529a6a04c152aefd4e3c (diff) | |
download | forums-4844b007771f71973db2fa440d3c8ef9057d1b02.tar forums-4844b007771f71973db2fa440d3c8ef9057d1b02.tar.gz forums-4844b007771f71973db2fa440d3c8ef9057d1b02.tar.bz2 forums-4844b007771f71973db2fa440d3c8ef9057d1b02.tar.xz forums-4844b007771f71973db2fa440d3c8ef9057d1b02.zip |
[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
Diffstat (limited to 'phpBB/includes/acp/acp_modules.php')
-rw-r--r-- | phpBB/includes/acp/acp_modules.php | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 52033b590c..2a533056b4 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -316,7 +316,7 @@ class acp_modules } // Name options - $s_name_options .= '<option value="' . $option . '"' . (($option == $module_data['module_basename']) ? ' selected="selected"' : '') . '>' . $this->lang_name($values['title']) . ' [' . $this->module_class . '_' . $option . ']</option>'; + $s_name_options .= '<option value="' . $option . '"' . (($option == $module_data['module_basename']) ? ' selected="selected"' : '') . '>' . $this->lang_name($values['title']) . ' [' . $option . ']</option>'; $template->assign_block_vars('m_names', array('NAME' => $option, 'A_NAME' => addslashes($option))); @@ -480,7 +480,7 @@ class acp_modules foreach ($module_infos as $option => $values) { // Name options - $s_install_options .= '<optgroup label="' . $this->lang_name($values['title']) . ' [' . $this->module_class . '_' . $option . ']">'; + $s_install_options .= '<optgroup label="' . $this->lang_name($values['title']) . ' [' . $option . ']">'; // Build module modes foreach ($values['modes'] as $m_mode => $m_values) @@ -539,57 +539,78 @@ class acp_modules if (!$module) { - $dh = @opendir($directory); + global $phpbb_extension_manager; - if (!$dh) - { - return $fileinfo; - } + $finder = $phpbb_extension_manager->get_finder(); + + $modules = $finder + ->suffix('_module') + ->directory("/$module_class") + ->default_path("includes/$module_class/info/") + ->default_suffix('') + ->default_prefix($module_class . '_') + ->default_directory('') + ->get_classes(); - while (($file = readdir($dh)) !== false) + foreach ($modules as $module) { - // Is module? - if (preg_match('/^' . $module_class . '_.+\.' . $phpEx . '$/', $file)) + // If the class does not exist it might be following the old + // format. phpbb_acp_info_acp_foo needs to be turned into + // acp_foo_info and the respective file has to be included + // manually because it does not support auto loading + if (!class_exists($module)) { - $class = str_replace(".$phpEx", '', $file) . '_info'; - - if (!class_exists($class)) + $info_class = str_replace("phpbb_{$module_class}_info_", '', $module) . '_info'; + if (file_exists($directory . $info_class . '.' . $phpEx)) { - include($directory . $file); + include($directory . $info_class . '.' . $phpEx); } + } + else + { + $info_class = preg_replace('/_module$/', '_info', $module); + } - // Get module title tag - if (class_exists($class)) - { - $c_class = new $class(); - $module_info = $c_class->module(); - $fileinfo[str_replace($module_class . '_', '', $module_info['filename'])] = $module_info; - } + if (class_exists($info_class)) + { + $info = new $info_class(); + $module_info = $info->module(); + + $main_class = (isset($module_info['filename'])) ? $module_info['filename'] : $module; + + $fileinfo[$main_class] = $module_info; } } - closedir($dh); ksort($fileinfo); } else { - $filename = $module_class . '_' . basename($module); - $class = $module_class . '_' . basename($module) . '_info'; - - if (!class_exists($class)) + if (!class_exists($module)) { - include($directory . $filename . '.' . $phpEx); + if (file_exists($directory . $module . '.' . $phpEx)) + { + include($directory . $module . '.' . $phpEx); + } + $info_class = $module . '_info'; + } + else + { + $info_class = preg_replace('/_module$/', '_info', $module); } // Get module title tag - if (class_exists($class)) + if (class_exists($info_class)) { - $c_class = new $class(); - $module_info = $c_class->module(); - $fileinfo[str_replace($module_class . '_', '', $module_info['filename'])] = $module_info; + $info = new $info_class(); + $module_info = $info->module(); + + $main_class = (isset($module_info['filename'])) ? $module_info['filename'] : $module; + + $fileinfo[$main_class] = $module_info; } } - + return $fileinfo; } |