In addition to the proposed design in the first post, but this goes somewhat against the current design implementation in the development branch for it.
Modify the existing 3.0 hooks system to fit our needs and wants.
Notes:
- Hook means a single point in the code where additional code can be run.
- Plugin means a package which may use one or more hooks to modify the phpBB system without editing files.
Change the hook class to use static methods
- No more declaring global $phpbb_hook in order to use it
Remove the requirement of sending the list (array) of valid hooks to the hook class
- It's simply not reasonable to have a list of valid hooks for 3.1, as there will be too many hooks.
- Adding hooks becomes a real PITA with requiring the declaration of valid hooks before allowing the new hook to be called
- Any invalid registers by plugins (registering a hook that does not exist) is not a problem (it'll just never be called)
Simplify the use model for hooks, three common needs are satisfied by hooks:
- Taking over a function completely to replace it with your own (should only rarely occur)
- Modifying data (input and output)
- Outputing additional data to the template
Two main styles of hooks can accomplish that:
- Taking over a function; this looks similar, though simplified, to what we use already:
- Code: Select all
// If boolean false is returned, that means something has taken over the function
if (phpbb_hook::call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id) === false)
{
return;
}
- Modifying data could look like this:
- Code: Select all
// Here we can modify some variables
extract(phpbb_hook:call_hook(array('posting', 'submit'), compact('sql_data', 'poll_data', ...)));
// Or a simpler version for sending a single variable for modification:
extract(phpbb_hook:call_hook(array('posting', 'test'), $test_variable));
- Outputting additional data to the template (or for other reasons) in key areas without the need for data modification:
- Code: Select all
// This is easy
phpbb_hook::call_hook(array('foo', 'bar'));
Expanding hooks into templates:
- Option one: simply add extra template variables for plugins to use to the template
This is a bit ugly and requires a bunch of unique template variable names.
Probably requires that we create our own output function in the hooks class to prevent overwritting of others and enforce it's use - Option two: Add a new kind of template variable for hooks
It could look like:
{HOOK posting, userdata}
This is not as ugly, does not require long unique variable names, and is not prone to overwriting
Requires we create our own output function in the hooks class to output what the plugin wants
Allowing templates to act like plugins too only for when that template is loaded:
- When a template is used, a check for a plugins.php file would be made by the hooks system.
This greatly increases the flexibility for tweaking some data sent to the user, allowing styles to become even more customised. - A warning during installation of a style if the plugins file exists and a global on/off for template plugins (like the PHP include)
Plugins (packages):
- The current method of just dropping a plugin file in a directory and it automatically starting up does not fit the user's needs
Users should be able to install, enable, disable, and uninstall plugins
- Install:
The installation method is what is required first, it allows plugins to easily handle any DB alterations required before installation
- Enable/Disable:
Enables or disables the plugin without uninstalling (losing) what is stored in the database.
- Uninstall:
Removes any changes made to the database as well (the plugin handles it through an uninstall method)
- A new ACP page is created to list installed/uninstalled hooks and manage them.
- A database table holds the list of currently installed plugins which are to be loaded at runtime.
- At runtime the plugin files are included and register the locations that they need.
- There is a slight problem that could come up here however. In the instance where a change to an existing DB table is made and a plugin is disabled.
- This may cause SQL errors in some cases.
- In order to prevent this we can do two things:
- Plugins can specify that they are not able to be disabled (requires uninstallation to disable)
- This is the easiest method, but data will be lost for temporary disables
- Plugins can specify some specific items to be called if they are installed but disabled
- A bit more difficult, but data will be saved without SQL errors
If something here isn't clear just ask, I wrote this up on little sleep after a long day.
