Author: John Reese
Status: Feedback / Bugfixing
This is a proposal for a very lightweight method of including a plugin/hook system for Mantis. It should be able to handle not only minor enhancements for areas such as outputting text, but adding new pages, menu items, and entire features to the application. It should be very simple, but very powerful.
This feature is meant as a counter point to the Add-Ons Support Requirements by offering a much simpler and easier to use plugin system without sacrificing flexibility or power.
Plugins will be very simple packages, extracted into the Mantis/plugins directory and enabled through the Management interface. There will be a simple event system that will handle hooking functionality in various forms, including data processing, list retrieval, and output. Events will be called at various points in the normal flow of Mantis, and the plugin API will handle calling any necessary plugin functions.
When a plugin is loaded at runtime, it will register basic information about itself to Mantis, including its name, author, description, version, and dependencies (Mantis version, other plugins). It will then register a callback function for each event that it would like to handle. When an event occurs, any plugin callbacks will be called in the order they are registered. The event type will determine how callback parameters and return values are processed.
New content pages will be added by creating scripts in a special directory of the plugin, and links to that page will be created with an API call to simplify the task. Plugin pages will not need to load the Mantis core, but will need to call the html_page_top() or html_page_bottom() functions as necessary.
To simplify the usage of language files, plugins will simply need to supply a lang/
directory with appropriate strings files. The language API will search for strings in the main language files first, and only load the current plugin's language files if a needed string is not found elsewhere.
There will need to be a simple and unified method for plugins to maintain their database schema, otherwise plugins will get released without proper upgrade paths for users. The plugin manager should provide an automated schema upgrade mechanism that works the same as the Mantis upgrade mechanism. For performance reasons, the schema for plugins should only be checked when the plugin management screens are accessed, where it should notify the user of the need to upgrade the schema.
These should be the basic event types, from which all (or most) events can be formed.
Execute event
Output event
Chain event
Default event
mantis_plugin_table
plugins_enabled
(default ON)manage_plugin_threshold
(default ADMINISTRATOR)
This flow of action should occur during normal Mantis execution. It should be possible to bypass this by either disabling plugins from config_inc.php
or by a page declaring a special flag before including core.php
.
plugins/<basename>/register.php
plugin_callback_<basename>_info()
functionplugin_callback_<basename>_register()
functionThis flow of action should occur whenever an event is signaled, assuming plugins are enabled.
plugins/<basename>/events.php
plugin_event_<basename>_<function_name>()
<basename> represents the plugin's directory name, and should be a short, unique name that does not include version names or other changing identifiers. 'mantis' is a reserved basename, and represents a virtual plugin used for allowing dependencies based on Mantis versions.
mantis/ plugins/ <basename>/ register.php events.php lang/ ... pages/ ...
register.php
is the only file required for a plugin to be valid. It must contain two callbacks for plugin information and event registrations. This file should only have the following callbacks, but may include additional functions or callbacks for more complex plugins. plugin_callback_<basename>_info()
- This function must return an array of plugin information, including name, version, ad dependencies. plugin_callback_<basename>_init()
- This function must set up the plugin, and hook any events needed.plugin_callback_<basename>_schema()
- This function is only required if the plugin needs to maintain changes or additions to the Mantis schema. It must return an array of schema upgrades in the same format as the admin/schema.php
upgrade script.events.php
is required for using event hooks. It should contain all the event callback functions, or include additional scripts with the necessary callbacks. All event callback functions must be named as plugin_event_callback_<basename>_<name>()
. This script will only be loaded if the plugin has registered for an event.lang/
is only required if the plugin needs to use language strings that don't appear in the standard language files. These files will only be loaded if the requested strings cannot be found otherwise.pages/
is only required if a plugin needs to have its own pages. They can be accessed by linking a url returned by the plugin_page()
function. These pages need not load the core libraries, as it will already be loaded for them.This is a very minimal plugin.
Directory Structure
mantis/ plugins/ supercow/ register.php events.php
sample/register.php
<?php /** * Return plugin details to the API. * @return array Plugin details */ function plugin_callback_supercow_info() { return array( 'name' => 'Super Cow Powers', 'description' => 'Gives your Mantis installation super cow powers.', 'version' => '1.0', 'author' => 'John Reese', 'contact' => 'jreese@leetcode.net', 'url' => 'http://leetcode.net', ); } /** * Intitialize the plugin. */ function plugin_callback_supercow_init() { plugin_event_hook( 'EVENT_PLUGIN_INIT', 'header' ); }
sample/events.php
<?php /** * Handle the EVENT_PLUGIN_INIT callback. */ function plugin_event_supercow_header() { header( 'X-Mantis: This Mantis has super cow powers.' ); }
plugin_callback_<basename>_register()
be plugin_callback_<basename>_init()
?