Stanislav Yordanov
[squirrelmail.git] / functions / plugin.php
CommitLineData
7b086a80 1<?php
2
35586184 3/**
4 * plugin.php
5 *
0606ca1f 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file provides the framework for a plugin architecture.
10 *
11 * Documentation on how to write plugins might show up some time.
12 *
13 * $Id$
14 */
15
35586184 16global $squirrelmail_plugin_hooks;
0a17ec32 17$squirrelmail_plugin_hooks = array();
2d367c68 18
0606ca1f 19/* This function adds a plugin. */
20function use_plugin ($name) {
21 if (file_exists("../plugins/$name/setup.php")) {
22 include_once("../plugins/$name/setup.php");
23 $function = "squirrelmail_plugin_init_$name";
24 if (function_exists($function)) {
25 $function();
2d367c68 26 }
2d367c68 27 }
0606ca1f 28}
2d367c68 29
0606ca1f 30/* This function executes a hook. */
31function do_hook ($name) {
32 global $squirrelmail_plugin_hooks;
33 $data = func_get_args();
a3439b27 34
0606ca1f 35 if (isset($squirrelmail_plugin_hooks[$name])
36 && is_array($squirrelmail_plugin_hooks[$name])) {
37 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
38 /* Add something to set correct gettext domain for plugin. */
39 if (function_exists($function)) {
40 $function($data);
dd389be5 41 }
2d367c68 42 }
2d367c68 43 }
7b086a80 44
0606ca1f 45 /* Variable-length argument lists have a slight problem when */
46 /* passing values by reference. Pity. This is a workaround. */
47 return $data;
48}
7b086a80 49
0606ca1f 50/*************************************/
51/*** MAIN PLUGIN LOADING CODE HERE ***/
52/*************************************/
53
54/* On startup, register all plugins configured for use. */
55if (isset($plugins) && is_array($plugins)) {
56 foreach ($plugins as $name) {
57 use_plugin($name);
2d367c68 58 }
0606ca1f 59}
076c01d7 60
35586184 61?>