[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
This commit is contained in:
Nils Adermann 2011-08-22 03:19:17 -04:00
parent f6632fcfd0
commit 4844b00777
2 changed files with 96 additions and 77 deletions

View file

@ -316,7 +316,7 @@ class acp_modules
} }
// Name options // 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))); $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) foreach ($module_infos as $option => $values)
{ {
// Name options // 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 // Build module modes
foreach ($values['modes'] as $m_mode => $m_values) foreach ($values['modes'] as $m_mode => $m_values)
@ -539,54 +539,75 @@ class acp_modules
if (!$module) if (!$module)
{ {
$dh = @opendir($directory); global $phpbb_extension_manager;
if (!$dh) $finder = $phpbb_extension_manager->get_finder();
{
return $fileinfo;
}
while (($file = readdir($dh)) !== false) $modules = $finder
->suffix('_module')
->directory("/$module_class")
->default_path("includes/$module_class/info/")
->default_suffix('')
->default_prefix($module_class . '_')
->default_directory('')
->get_classes();
foreach ($modules as $module)
{ {
// Is module? // If the class does not exist it might be following the old
if (preg_match('/^' . $module_class . '_.+\.' . $phpEx . '$/', $file)) // 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'; $info_class = str_replace("phpbb_{$module_class}_info_", '', $module) . '_info';
if (file_exists($directory . $info_class . '.' . $phpEx))
if (!class_exists($class))
{ {
include($directory . $file); include($directory . $info_class . '.' . $phpEx);
}
// 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;
} }
} }
else
{
$info_class = preg_replace('/_module$/', '_info', $module);
}
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); ksort($fileinfo);
} }
else else
{ {
$filename = $module_class . '_' . basename($module); if (!class_exists($module))
$class = $module_class . '_' . basename($module) . '_info';
if (!class_exists($class))
{ {
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 // Get module title tag
if (class_exists($class)) if (class_exists($info_class))
{ {
$c_class = new $class(); $info = new $info_class();
$module_info = $c_class->module(); $module_info = $info->module();
$fileinfo[str_replace($module_class . '_', '', $module_info['filename'])] = $module_info;
$main_class = (isset($module_info['filename'])) ? $module_info['filename'] : $module;
$fileinfo[$main_class] = $module_info;
} }
} }

View file

@ -440,7 +440,8 @@ class p_master
trigger_error('Module not accessible', E_USER_ERROR); 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) && !class_exists("{$this->p_class}_$this->p_name"))
{ {
if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) 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); 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)) if (!empty($mode))
{
$this->p_mode = $mode;
}
// 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 $class_name($this);
// 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'])
{ {
$this->p_mode = $mode; $icat = $this->module_ary[$this->active_module_row_id]['parent'];
} }
// Create a new instance of the desired module ... if it has a // Not being able to overwrite ;)
// constructor it will of course be executed $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
$instance = "{$this->p_class}_$this->p_name"; }
else
$this->module = new $instance($this); {
// If user specified the module url we will use it...
// We pre-define the action parameter we are using all over the place if ($module_url !== false)
if (defined('IN_ADMIN'))
{ {
// Is first module automatically enabled a duplicate and the category not passed yet? $this->module->u_action = $module_url;
if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate'])
{
$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) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
} }
else else
{ {
// If user specified the module url we will use it... $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name'];
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) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
} }
// Add url_extra parameter to u_action url $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
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'];
}
// Assign the module path for re-usage // Add url_extra parameter to u_action url
$this->module->module_path = $module_path . '/'; 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 // Assign the module path for re-usage
// Users are able to call the main method after this function to be able to assign additional parameters manually $this->module->module_path = $module_path . '/';
if ($execute_module)
{
$this->module->main($this->p_name, $this->p_mode);
}
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);
} }
} }