Fix broken subject line that I doubt has worked since we went rg=0
[squirrelmail.git] / functions / plugin.php
CommitLineData
7b086a80 1<?php
2
35586184 3/**
4 * plugin.php
5 *
76911253 6 * Copyright (c) 1999-2003 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) {
bd9c880b 21 if (file_exists(SM_PATH . "plugins/$name/setup.php")) {
22 include_once(SM_PATH . "plugins/$name/setup.php");
0606ca1f 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. */
31524bcd 31function do_hook ($name) {
0606ca1f 32 global $squirrelmail_plugin_hooks;
33 $data = func_get_args();
2586d588 34 $ret = '';
a3439b27 35
0606ca1f 36 if (isset($squirrelmail_plugin_hooks[$name])
37 && is_array($squirrelmail_plugin_hooks[$name])) {
38 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
39 /* Add something to set correct gettext domain for plugin. */
40 if (function_exists($function)) {
31524bcd 41 $function($data);
42 }
43 }
44 }
45
46 /* Variable-length argument lists have a slight problem when */
47 /* passing values by reference. Pity. This is a workaround. */
48 return $data;
49}
50
51/* This function executes a hook. */
52function do_hook_function($name,$parm=NULL) {
53 global $squirrelmail_plugin_hooks;
54 $ret = '';
55
56 if (isset($squirrelmail_plugin_hooks[$name])
57 && is_array($squirrelmail_plugin_hooks[$name])) {
58 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
59 /* Add something to set correct gettext domain for plugin. */
60 if (function_exists($function)) {
61 $ret = $function($parm);
dd389be5 62 }
2d367c68 63 }
2d367c68 64 }
7b086a80 65
0606ca1f 66 /* Variable-length argument lists have a slight problem when */
67 /* passing values by reference. Pity. This is a workaround. */
2586d588 68 return $ret;
0606ca1f 69}
7b086a80 70
09ac2863 71/* This function executes a hook. */
72function concat_hook_function($name,$parm=NULL) {
73 global $squirrelmail_plugin_hooks;
74 $ret = '';
31524bcd 75
09ac2863 76 if (isset($squirrelmail_plugin_hooks[$name])
77 && is_array($squirrelmail_plugin_hooks[$name])) {
78 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
79 /* Concatenate results from hook. */
80 if (function_exists($function)) {
81 $ret .= $function($parm);
82 }
83 }
84 }
85
86 /* Variable-length argument lists have a slight problem when */
87 /* passing values by reference. Pity. This is a workaround. */
88 return $ret;
89}
cd7fc9e6 90
91/**
92 * This function checks whether the user's USER_AGENT is known to
93 * be broken. If so, returns true and the plugin is invisible to the
94 * offending browser.
95 */
96function soupNazi(){
97
cd7fc9e6 98 $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
99 'Opera/4', 'OmniWeb', 'Lynx');
100 foreach($soup_menu as $browser) {
0b97a708 101 if(stristr($_SERVER['HTTP_USER_AGENT'], $browser)) {
cd7fc9e6 102 return 1;
103 }
104 }
105 return 0;
106}
0606ca1f 107/*************************************/
108/*** MAIN PLUGIN LOADING CODE HERE ***/
109/*************************************/
110
111/* On startup, register all plugins configured for use. */
112if (isset($plugins) && is_array($plugins)) {
113 foreach ($plugins as $name) {
114 use_plugin($name);
2d367c68 115 }
0606ca1f 116}
076c01d7 117
b68edc75 118?>