mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[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:
parent
f6632fcfd0
commit
4844b00777
2 changed files with 96 additions and 77 deletions
|
@ -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();
|
||||
|
||||
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 (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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
include($directory . $info_class . '.' . $phpEx);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <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"))
|
||||
{
|
||||
|
@ -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))
|
||||
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
|
||||
// constructor it will of course be executed
|
||||
$instance = "{$this->p_class}_$this->p_name";
|
||||
|
||||
$this->module = new $instance($this);
|
||||
|
||||
// We pre-define the action parameter we are using all over the place
|
||||
if (defined('IN_ADMIN'))
|
||||
// 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)
|
||||
{
|
||||
// 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'];
|
||||
}
|
||||
|
||||
// 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}";
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue