Plugin

From FUDforum Wiki
(Redirected from Plugins)
Jump to: navigation, search

A plugin (sometimes called an addin, or extension) is a PHP script that interacts with FUDforum to provide a certain, usually very specific, function "on demand". For example, to implement new BBcode tags, send new users a welcome PM (private message), authenticate users against an LDAP directory or to check registering users against the BotScout API.

Plugin support was introduced in FUDforum version 2.8.1.

Contents

[edit] Developing new plugins

To develop a new pluging, create a new *.plugin file in your forum's FUDdata/plugins directory or create a new subdirectory for it. All plugins must implement one or more hooks by writing PHP functions to handle them.

All BBCode plugins should have functions for both BBCODE2HTML (convert the tag to HTML) and HTML2BBCODE (convert the HTML back to a tag).

Authentication plugins should return either 0 (deny access) or 1 (allow access). It is the plugin's responsibility to register users in the FUDforum database and sync their passwords before allowing them through.

Plugins may also have optional pluginname_enable() and pluginname_disable() functions that will be executed when the plugin is either activated or deactivated from the Plugin Manager admin control panel.

Info Symbol WARNING: If you change existing plugins, copy them to new names to prevent subsequent upgraded from overwriting your changes.

[edit] Available hooks

FUDforum provides the following hooks. More hooks will be added as and when required:

Hook/ Call-out Introduced Description
AUTHENTICATE 2.8.1 Authenticate users against an external source like an LDAP directory.
INITUSER 2.8.1 Initialize user session. Great for setting themes based on the browser's language or routing mobile phones to a "lo-fi" theme.
BBCODE2HTML 2.8.1 Convert BBcode tags to HTML (as message gets posted).
HTML2BBCODE 2.8.1 Convert HTML code to BBcode tags (edit post).
PREREGISTRATION 2.8.1 Additional checks before allowing a user to register. For example, checks against the Botscout API or assign user an avatar image.
EMAILCONFIRMED 2.8.1 User confirmed his account after registration. Great for sending a welcome message or PM.
CAPTCHA 3.0.0 Define a custom CAPTCHA challenge and response to display instead of the default built-in CAPTCHA.
CAPTCHA_VALIDATE 3.0.0 Validate the user's response to a CAPTCH challenge in case it wasn't supplied with the CAPTCHA hook.

[edit] Example plugins

Here is an example plugin that implements a new [TEST] BBcode tag:

// Initialize plugin
plugin_add_hook("BBCODE2HTML", "plugin_test_tag_to_html");
plugin_add_hook("HTML2BBCODE", "plugin_test_html_to_tag");

// Convert [TEST] to html code (new post submitted)
function plugin_test_tag_to_html($array) {
        list($bbcode) = $array;
        $bbcode = str_replace('[TEST]', 'Test tag expanded', $bbcode);
        return array($bbcode);
}

// Convert html to [TEST] tag (message edited)
function plugin_test_html_to_tag($array) {
        list($bbcode) = $array;
        $bbcode = str_replace('Test tag expanded', '[TEST]', $bbcode);
        return array($bbcode);
}

An example authentication plugin:

plugin_add_hook('AUTHENTICATE', 'plugin_simple_auth');

function plugin_simple_auth($data) {
	list($login, $password) = $data;
 	if ($login == 'admin') return 1;	// Always allow admin through

	if ($login == 'scott' && $password == 'tiger') {	// Is valid user?
 		if (!($usr_d = db_sab('SELECT id, passwd FROM '.$GLOBALS['DBHOST_TBL_PREFIX'].'users WHERE login='._esc($login)))) {
			$uent = new fud_user_reg;	// Register as FUDforum user
			$uent->users_opt = -1;
			$uent->login = $login;
			$uent->plaintext_passwd = $password;
			$uent->add_user();
		} else if (md5($password) != $usr_d->passwd) {
			$uent = new fud_user_reg;	// Sync password
			$uent->id = $usr_d->id;
			$uent->plaintext_passwd = $password;
			$uent->sync_user();
		}
		return 1;	// Allow access
	}

	return 0;		// Deny access
}

[edit] Optional call-outs

Optional call-outs functions can be coded in *.plugin files. The functions are named plugin_func(), where plugin is the plugin's name.

[edit] plugin_info

Return more information about the plugin to the plugin manager. Example:

function ldap_info() {
       return array('name' => 'LDAP Authentication',
                    'desc' => 'Authenticate forum users from an LDAP...',
                    'version' => '1.2');
}

[edit] plugin_enable

Check prerequisites and install the plugin (add DB tables, change files). This function should return NULL (everything is OK), or an error message.

[edit] plugin_disable

Deinstall the plugin. This function should return NULL (everything is OK), or an error message.

[edit] plugin_config

Configure the plugin. Display configuration fields and allow the users to change config values.

[edit] Also see

  • Plugin Manager, part of the Admin Control Panel that allows administrators to activate or deactivate plugins.
  • Plugin directory, list of available plugins.

[edit] External links

Languages
Personal tools