Fixed some E_ALL warnings, should now be E_ALL clean.
[squirrelmail.git] / functions / plugin.php
... / ...
CommitLineData
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
16global $squirrelmail_plugin_hooks;
17$squirrelmail_plugin_hooks = array();
18
19/* This function adds a plugin. */
20function use_plugin ($name) {
21 if (file_exists(SM_PATH . "plugins/$name/setup.php")) {
22 include_once(SM_PATH . "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. */
31function do_hook ($name) {
32 global $squirrelmail_plugin_hooks;
33 $data = func_get_args();
34 $ret = '';
35
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)) {
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);
62 }
63 }
64 }
65
66 /* Variable-length argument lists have a slight problem when */
67 /* passing values by reference. Pity. This is a workaround. */
68 return $ret;
69}
70
71
72
73/**
74 * This function checks whether the user's USER_AGENT is known to
75 * be broken. If so, returns true and the plugin is invisible to the
76 * offending browser.
77 */
78function soupNazi(){
79
80 $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
81 'Opera/4', 'OmniWeb', 'Lynx');
82 foreach($soup_menu as $browser) {
83 if(stristr($_SERVER['HTTP_USER_AGENT'], $browser)) {
84 return 1;
85 }
86 }
87 return 0;
88}
89/*************************************/
90/*** MAIN PLUGIN LOADING CODE HERE ***/
91/*************************************/
92
93/* On startup, register all plugins configured for use. */
94if (isset($plugins) && is_array($plugins)) {
95 foreach ($plugins as $name) {
96 use_plugin($name);
97 }
98}
99
100?>