WIKINDX ~ Plug-in Modules

This file describes how to write a basic plug-in for WIKINDX.

There are two types of plug-ins:

menu plug-ins
inline plug-ins


Menu plug-ins

Menu plug-ins have one or more menu items inserted in the WIKINDX menu specified in the plug-in. These types of plug-ins are intended for the cases where the main display table of the WIKINDX is completely dedicated to the plug-in.

Example:

/****************************
**** Plug-in module example ****
      **** index.php ****
*****************************/

class example_MODULE
{
// constructor
	function example_MODULE($db, $vars, $menuInit = FALSE)
	{
		if($menuInit)
		{
			$this->menus = array(	"wikindx" => 
						array("Module"		=>	"example"),
									"help" 	=>
						array("Module Help"	=>	"helpMe"),
			);
// $authorize: 0 -> menu item displayed for all users
// 1 -> menu item displayed for users with write access
// 2 -> menu item displayed only for admins.
$this->authorize = 1; return; // Need do nothing more as this is simply menu initialisation. } $this->db = $db; $this->vars = $vars; // Load the template module include_once("core/template/TEMPLATE.php"); $this->template = new TEMPLATE('content'); } function example() { $title = "Module Example"; $this->template->setVar('heading', $title); if(array_key_exists('method', $this->vars)) $string = "The method is " . $this->vars['method'] . '.'; else $string = "No method was input."; $this->template->setVar('body', $string); return $this->template->process(); } function helpMe() { include_once("core/html/MISC.php"); $title = "Module HELP"; $this->template->setVar('heading', $title); $link = MISC::a("link", "this module", htmlentities("index.php?action=example_example&method=helpMePlease!")); $string = "No help here, try $link"; $this->template->setVar('body', $string); return $this->template->process(); } }

The constructor parameters $db and $vars are the database object (see the SQL class) and an array of all input values from the web browser form or query string. These are set to FALSE if the constructor is initialised from the MENU system in which case $menuInit will be TRUE.

$this->authorize controls the display of the module item in the menu system according to user permissions. This was added for WIKINDX v3.2.3.

To get your plug-ins working, a few conditions are required:

So, in the above example, and if the user has write access to the WIKINDX, an item Module is inserted in the wikindx menu with the action example and an item Module Help is inserted in the help menu with the action helpMe. In your class, there must exist the methods example() and helpMe().

You must use the templating system that WIKINDX uses and return the template string to the calling process as shown in the above example. Furthermore, in the interests of compatibility and future WIKINDX upgrades, you should use the WIKINDX functions where possible and as explained in the rest of this documentation.


Inline plug-ins

Inline plug-ins have no associated menu item. They produce content that is inserted either above or below the WIKINDX main display table on specified WIKINDX pages and are intended for content that is additional to the page being viewed.

Example:

/*****
* inlineExample_MODULE
*
* inline plug-in module simple example.
* 
*****/
class inlineExample_MODULE
{
// Constructor
	function inlineExample_MODULE($db, $vars)
	{
// These two are not needed here for this simple example but show how it is possible to interface with 
// the database or with user input in a plug-in module.
		$this->db = $db; // the database object.
		$this->vars = $vars; // the GET or POST querystring or form input array.
		include_once("core/html/MISC.php");
// Which page is this attached to?
// This should be the vars['action'] value as found in wikindx3/index.php.
		$this->pluginaction = 'front'; // The front page of the WIKINDX
		$this->plugintop = MISC::a("link", "click me to print at the bottom", 
			htmlentities("index.php?action=front&inlinePluginAction=inlineExample_bottomPrint"));
		$this->pluginbottom = FALSE; // print nothing at the bottom unless specified in method below.
	}
// If no method is supplied in the form input or querystring, this is the default method that is run.
// It must be the same name as the module.
// $this->plugintop or $this->pluginbottom contains the string that will be printed either above the normal 
// wikindx output table or below it.
	function bottomPrint()
	{
		$this->plugintop = FALSE; // print nothing at the top if we use this method.
		$this->pluginbottom = "I print below the standard output table";
	}
}

The constructor parameters $db and $vars are the database object (see the SQL class) and an array of all input values from the web browser form or query string.

To get your plug-ins working, a few conditions are required:

So, in the above example, on displaying the front page of WIKINDX, a hyperlink is displayed above the main display table. If the user clicks on this hyperlink, the front page is displayed again but with some text printed below the main display table.


If you write a module that you think may be of interest to other WIKINDX users, please consider releasing it under the GPL at Sourceforge -- contact sirfragalot@users.sourceforge.net for details on how to do this.

WIKINDX home      WIKINDX usage      WIKINDX classes