LnBlog stores all its plugins in a “plugins” directory. The plugins directory stores all the plugins that are present in an LnBlog installation. It may contain one or more subdirectories with names like “disabled” to store plugins which are not to be loaded.
|Using Plugins||LnBlog stores all its plugins in a “plugins” directory.|
|How plugins work||The plugin mechanism is really quite simple.|
|Adding new plugins||Adding a new plugins is as simple as copying the plugin PHP file into the plugins directory.|
|Removing plugins||To disable a plugin, go to the plugin loading configuration page and uncheck the “enabled” box for that plugin file.|
|Load order||As previously noted, load order is important for plugins that add segments to the page, such as sidebar plugins.|
|Writing plugins||LnBlog uses an event-based plugin system.|
The plugin mechanism is really quite simple. LnBlog LnBlog maintains two lists of plugins: disabled plugins (i.e. those that should not loaded) and plugins to should be loaded first. These lists can be set for the entire installation and can also be overridden for individual blogs. You can edit these lists through the “configure plugin loading” link.
When a page is loaded, LnBlog will do the following.
For plugins that write user-visible data, e.g. sidebar panels, the order in which they are loaded is important. For example, the sidebar panels are displayed in the order in which they are loaded. If you want to change the order in which the sidebar panels appear, then you should change the order in which those plugins are loaded.
Adding a new plugins is as simple as copying the plugin PHP file into the plugins directory. If a plugin requires any additional installation steps, it should be noted in the plugin documentation.
It is also possible to install plugins on a per-blog basis. To do this, create a directory named “plugins” in the blog root directory and copy the plugin file there.
As previously noted, load order is important for plugins that add segments to the page, such as sidebar plugins. To change this order, go to the plugin loading configuration page and change the numbers in the load order column to reflect your desired order. Note that these numbers are relative to each other and will be normalized when the list is saved, so they do not need to be continuous, i.e. missing or doubled numbers are not necessarily an error. Entering a non-numeric value will be interpreted as an unspecified load order.
LnBlog uses an event-based plugin system. That means that LnBlog sends out messages when certain things happen, such as a page being displayed or an entry being added. Plugins work by registering themselves with the event manager and asking to be run when certain events are fired.
The actual coding of a plugin can be done in several ways. The recommended method is to create a class for your plugin which inherits from the abstract Plugin class, as this will allow you to inherit certain basic functionality. Beyond that, it depends on what you want to do. The back-end classes mostly allow for auto-detection of identifiers, so, for example, you can simply do something like
$myblog = NewBlog();
to get access to information on the current weblog. The same thing works for entries and articles, although individual comments generally need an explicit identifier. Of course, it is always possible to simply create an instance of the parent entry of a comment and get a list of comments that way.
The plugins/disabled directory of the default LnBlog installation includes a template.php file. This is a heavily commented plugin template which is intended as a learning tool. Between this and the standard set of plugins, it should be possible to get a good idea of how the plugin system works.