Document: Using Plugins

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.

Section: How plugins work

The plugin mechanism is really quite simple.  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 looks at the plugins directory to get a list of all the plugins that are 
present and sorts them in alphabetical order by file name.  It removes the plugins in the disabled 
list and moves the ones in the "load first" list to the front.  It then loads the plugins in the resulting
list in order.

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.

Section: Adding new plugins

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.

Section: Removing plugins

To disable a plugin, go to the plugin loading configuration page and uncheck the "enabled"
box for that plugin file.  To uninstall a plugin, just delete the file or move it out of the 
plugins directory.

Section: Load order

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.

Section: Writing plugins

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.