| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * plugin.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2001 The SquirrelMail Development Team |
| 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 | |
| 16 | /*****************************************************************/ |
| 17 | /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ |
| 18 | /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ |
| 19 | /*** + Base level indent should begin at left margin, as ***/ |
| 20 | /*** the first line of the function definition below. ***/ |
| 21 | /*** + All identation should consist of four space blocks ***/ |
| 22 | /*** + Tab characters are evil. ***/ |
| 23 | /*** + all comments should use "slash-star ... star-slash" ***/ |
| 24 | /*** style -- no pound characters, no slash-slash style ***/ |
| 25 | /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ |
| 26 | /*** ALWAYS USE { AND } CHARACTERS!!! ***/ |
| 27 | /*** + Please use ' instead of ", when possible. Note " ***/ |
| 28 | /*** should always be used in _( ) function calls. ***/ |
| 29 | /*** Thank you for your help making the SM code more readable. ***/ |
| 30 | /*****************************************************************/ |
| 31 | |
| 32 | global $squirrelmail_plugin_hooks; |
| 33 | $squirrelmail_plugin_hooks = array(); |
| 34 | |
| 35 | // This function adds a plugin |
| 36 | function use_plugin ($name) { |
| 37 | |
| 38 | if (file_exists("../plugins/$name/setup.php")) { |
| 39 | include_once("../plugins/$name/setup.php"); |
| 40 | $function = "squirrelmail_plugin_init_$name"; |
| 41 | if (function_exists($function)) { |
| 42 | $function(); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |
| 48 | // This function executes a hook |
| 49 | function do_hook ($name) { |
| 50 | global $squirrelmail_plugin_hooks; |
| 51 | $data = func_get_args(); |
| 52 | |
| 53 | if (isset($squirrelmail_plugin_hooks[$name]) |
| 54 | && is_array($squirrelmail_plugin_hooks[$name])) { |
| 55 | foreach ($squirrelmail_plugin_hooks[$name] as $function) { |
| 56 | // Add something to set correct gettext domain for plugin |
| 57 | if (function_exists($function)) { |
| 58 | $function($data); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Variable-length argument lists have a slight problem when |
| 64 | // passing values by reference. Pity. This is a workaround. |
| 65 | return $Data; |
| 66 | } |
| 67 | |
| 68 | /* -------------------- MAIN --------------------- */ |
| 69 | |
| 70 | // On startup, register all plugins configured for use |
| 71 | if (isset($plugins) && is_array($plugins)) { |
| 72 | foreach ($plugins as $name) { |
| 73 | use_plugin($name); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | ?> |