Plugin

Abstract class for plugins.  Plugins can inherit from this class to get default configuration functionality.  They can also override the configuration methods to do custom configuration.  Inherits: LnBlogObject

Summary
PluginAbstract class for plugins.
Properties
plugin_descA short description of the plugin.
plugin_versionThe version number of the plugin.
member_listAn associative array of arrays, with the form member=>settings, where member is the name of a member variable of your class and settings is an associative array of the configuration data for that member.
Functions
addOptionA short-hand way to add configuration options.
showConfigDisplays the plugin configuration in an HTML form.
updateConfigRetrieves configuration data for the plugin from an HTTP POST and stores the data in the relevant files.
getConfigReads the configuration data for the plugin from a file and stores it in class variables.
Cache management functions
Functions
cachepathGets the path to the cache file for this plugin.
invalidateCacheInvalidates, i.e.
buildOutputMethod called by outputCache to regenerate cache data.
outputCacheDumps the contents of the cache file to the browser.
registerStandardInvalidatorsRegisters the standard set of cache invalidator events.
getCacheReturns the contents of the cache file as a string.

Properties

plugin_desc

A short description of the plugin.

plugin_version

The version number of the plugin.  This should be in “1.2.3” format.

member_list

An associative array of arrays, with the form member=>settings, where member is the name of a member variable of your class and settings is an associative array of the configuration data for that member.  This array is used by the default configuration show/save methods.

The following is a list of possible configuration settings for a member variable.  If a setting is not given for a particular control, then the default value will be used.

descriptionA descriptive string for the variable.  This will be displayed on the configuration screen when the user modifies the setting for this variable.  This element is required.
controlThe type of control used to display this variable on the configuration screen.  For the most part, these map directly to HTML input element types.  The currently recognized values are “text”, “checkbox”, “radio”, “select”, “file”.  The default is “text”.
defaultThe default value for this variable.  This value will be used if the user does not specify a setting.  Also, if the user modifies other settings, no configuration entry will be saved for this variable if the value is still the default.  This is important because of pre-blog overriding.  The default is the empty string.
optionsAn array of the form value=>description, where the value keys are control values and the descriptions describe each choice for the user.  These are used only for radio button and selection box controls, with each array element representing an option for the user to select .

Functions

addOption

function addOption($name,  
$description,  
$default,  
$control = "text",
$options = false)

A short-hand way to add configuration options.  Adds the necessary values to member_list all in one shot.

Parameters

nameThe name of the option.
descriptionA short description for the user to see.
defaultThe default value.
controlOptional control to use.  The default is “text”.
optionsAn array of options for radio and select controls.

showConfig

function showConfig(&$page)

Displays the plugin configuration in an HTML form.  You must make sure to initialize the member_list for this to work.

Parameters

pageA reference to the page which will display the configuration.  This is useful for configs that need to add linked-in stylesheets or external Javascript files.

Returns

Optionally returns the form markup as a string.

updateConfig

function updateConfig()

Retrieves configuration data for the plugin from an HTTP POST and stores the data in the relevant files.

Note that this also handles uploaded files.  If run from a blog, the file is uploaded to the blog root.  Otherwise, it goes to the userdata directory.

Returns

True on success, false on failure.

getConfig

function getConfig()

Reads the configuration data for the plugin from a file and stores it in class variables.

Cache management functions

Summary
Functions
cachepathGets the path to the cache file for this plugin.
invalidateCacheInvalidates, i.e.
buildOutputMethod called by outputCache to regenerate cache data.
outputCacheDumps the contents of the cache file to the browser.
registerStandardInvalidatorsRegisters the standard set of cache invalidator events.
getCacheReturns the contents of the cache file as a string.

Functions

cachepath

function cachepath($obj)

Gets the path to the cache file for this plugin.  Note that there is, by default, only one such file per plugin.  Plugins that need more must override this method.

Parameters

objThe object to which the cache applies.  In the default implementation, this is the current blog.  Plugins which want to store cache data in an entry directory, or a path based on some other object, must override this method.

Returns

A string representing the local filesystem path to which cach data will be written.  In the default implementation, this has the form BLOGROOT/cache/PLUGINCLASS_output.cache.

invalidateCache

function invalidateCache($obj = false)

Invalidates, i.e. deletes, the cache file for this plugin.

Parameters

objSame as for cachepath.  If not specified, the current blog is used.  Note that this parameter is passed on to cachepath and so can be used for implementing multi-file caches.

buildOutput

function buildOutput($obj)

Method called by outputCache to regenerate cache data.  Plugins using the standard cache system must override this method to do their output.

Parameters

objAn object to which this cache applies, as with invalidateCache and others.

Returns

A string of data to send to the client.

outputCache

function outputCache($obj = false,
$suppress_login = true)

Dumps the contents of the cache file to the browser.  If the cache file exists, then the data comes from there.  Otherwise, buildOutput is called and the result used to create a fresh cache file.  Note that if the class has an enable_cache member and it is set to false, then the cache will be bypassed and only the result of buildOutput will be sent to the browser.

Parameters

objObject to which the cache applies.
suppress_loginDon’t display the cached data when the user is logged in.  This allows for users with different permission levels to still see different pages with caching on.

registerStandardInvalidators

function registerStandardInvalidators()

Registers the standard set of cache invalidator events.  This registers the invalidateCache method as an event handler for the UpdateComplete, InsertComplete, and DeleteComplete events for the BlogEntry and Article classes, as well as the UpdateComplete event of the blog class.

getCache

function getCache($obj = false)

Returns the contents of the cache file as a string.

Parameters

objObject to which the cache applies.

Returns

A string with the contents of the cache file.

function addOption($name,  
$description,  
$default,  
$control = "text",
$options = false)
A short-hand way to add configuration options.
function showConfig(&$page)
Displays the plugin configuration in an HTML form.
function updateConfig()
Retrieves configuration data for the plugin from an HTTP POST and stores the data in the relevant files.
function getConfig()
Reads the configuration data for the plugin from a file and stores it in class variables.
function cachepath($obj)
Gets the path to the cache file for this plugin.
function invalidateCache($obj = false)
Invalidates, i.e.
function buildOutput($obj)
Method called by outputCache to regenerate cache data.
function outputCache($obj = false,
$suppress_login = true)
Dumps the contents of the cache file to the browser.
function registerStandardInvalidators()
Registers the standard set of cache invalidator events.
function getCache($obj = false)
Returns the contents of the cache file as a string.
A base object which is event-aware, i.e.
Close