Applied patch #102655. Ha! my first commit !
[squirrelmail.git] / functions / plugin.php
CommitLineData
7b086a80 1<?php
2
3/**
4 ** plugin.php
5 **
6 ** This file provides the framework for a plugin architecture.
7 **
8 ** Plugins will eventually be a way to provide added functionality
9 ** without having to patch the SquirrelMail source code. Have some
c27d5a49 10 ** patience, though, as the these funtions might change in the near
7b086a80 11 ** future.
12 **
13 ** Documentation on how to write plugins might show up some time.
14 **
15 **/
16
17
18 $plugin_php = true;
19
20 // This function adds a plugin
21 function use_plugin ($name) {
6b638171 22 if (file_exists('../plugins/'.$name.'/setup.php')) {
23 include ('../plugins/'.$name.'/setup.php');
24 $function = 'squirrelmail_plugin_init_'.$name;
dd389be5 25 if (function_exists($function))
26 $function();
6b638171 27 }
7b086a80 28 }
29
30 // This function executes a hook
31 function do_hook ($name) {
32 global $squirrelmail_plugin_hooks;
dd389be5 33 $Data = func_get_args();
7b086a80 34 if (is_array($squirrelmail_plugin_hooks[$name])) {
dd389be5 35 foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
7b086a80 36 // Add something to set correct gettext domain for plugin
dd389be5 37 if (function_exists($function)) {
38 $function(&$Data);
39 }
7b086a80 40 }
41 }
dd389be5 42
43 // Variable-length argument lists have a slight problem when
44 // passing values by reference. Pity. This is a workaround.
45 return $Data;
46 }
7b086a80 47
48 // On startup, register all plugins configured for use
c27d5a49 49 if (is_array($plugins))
dd389be5 50 foreach ($plugins as $id => $name)
c27d5a49 51 use_plugin($name);
7b086a80 52
53?>