| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * plugin.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2002 The SquirrelMail Project 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 | global $squirrelmail_plugin_hooks; |
| 17 | $squirrelmail_plugin_hooks = array(); |
| 18 | |
| 19 | /* This function adds a plugin. */ |
| 20 | function 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(); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /* This function executes a hook. */ |
| 31 | function do_hook ($name) { |
| 32 | global $squirrelmail_plugin_hooks; |
| 33 | $data = func_get_args(); |
| 34 | |
| 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); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /* Variable-length argument lists have a slight problem when */ |
| 46 | /* passing values by reference. Pity. This is a workaround. */ |
| 47 | return $data; |
| 48 | } |
| 49 | |
| 50 | /*************************************/ |
| 51 | /*** MAIN PLUGIN LOADING CODE HERE ***/ |
| 52 | /*************************************/ |
| 53 | |
| 54 | /* On startup, register all plugins configured for use. */ |
| 55 | if (isset($plugins) && is_array($plugins)) { |
| 56 | foreach ($plugins as $name) { |
| 57 | use_plugin($name); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * This function checks whether the user's USER_AGENT is known to |
| 63 | * be broken. If so, returns true and the plugin is invisible to the |
| 64 | * offending browser. |
| 65 | */ |
| 66 | function soupNazi(){ |
| 67 | |
| 68 | global $HTTP_USER_AGENT, $SQSPELL_SOUP_NAZI; |
| 69 | |
| 70 | require_once('../plugins/squirrelspell/sqspell_config.php'); |
| 71 | |
| 72 | $soup_menu = explode( ',', $SQSPELL_SOUP_NAZI ); |
| 73 | return( in_array( trim( $HTTP_USER_AGENT ), $soup_menu ) ); |
| 74 | } |
| 75 | |
| 76 | ?> |