Finally, a fix for delete_move_next with thread sort. I _think_ this should do the...
[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
cd21d1aa 16require_once(SM_PATH . 'functions/global.php');
17
35586184 18global $squirrelmail_plugin_hooks;
0a17ec32 19$squirrelmail_plugin_hooks = array();
2d367c68 20
0606ca1f 21/* This function adds a plugin. */
22function use_plugin ($name) {
bd9c880b 23 if (file_exists(SM_PATH . "plugins/$name/setup.php")) {
24 include_once(SM_PATH . "plugins/$name/setup.php");
0606ca1f 25 $function = "squirrelmail_plugin_init_$name";
26 if (function_exists($function)) {
27 $function();
2d367c68 28 }
2d367c68 29 }
0606ca1f 30}
2d367c68 31
0606ca1f 32/* This function executes a hook. */
31524bcd 33function do_hook ($name) {
0606ca1f 34 global $squirrelmail_plugin_hooks;
35 $data = func_get_args();
2586d588 36 $ret = '';
a3439b27 37
0606ca1f 38 if (isset($squirrelmail_plugin_hooks[$name])
39 && is_array($squirrelmail_plugin_hooks[$name])) {
40 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
41 /* Add something to set correct gettext domain for plugin. */
42 if (function_exists($function)) {
31524bcd 43 $function($data);
44 }
45 }
46 }
47
48 /* Variable-length argument lists have a slight problem when */
49 /* passing values by reference. Pity. This is a workaround. */
50 return $data;
51}
52
53/* This function executes a hook. */
54function do_hook_function($name,$parm=NULL) {
55 global $squirrelmail_plugin_hooks;
56 $ret = '';
57
58 if (isset($squirrelmail_plugin_hooks[$name])
59 && is_array($squirrelmail_plugin_hooks[$name])) {
60 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
61 /* Add something to set correct gettext domain for plugin. */
62 if (function_exists($function)) {
63 $ret = $function($parm);
dd389be5 64 }
2d367c68 65 }
2d367c68 66 }
7b086a80 67
0606ca1f 68 /* Variable-length argument lists have a slight problem when */
69 /* passing values by reference. Pity. This is a workaround. */
2586d588 70 return $ret;
0606ca1f 71}
7b086a80 72
09ac2863 73/* This function executes a hook. */
74function concat_hook_function($name,$parm=NULL) {
75 global $squirrelmail_plugin_hooks;
76 $ret = '';
31524bcd 77
09ac2863 78 if (isset($squirrelmail_plugin_hooks[$name])
79 && is_array($squirrelmail_plugin_hooks[$name])) {
80 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
81 /* Concatenate results from hook. */
82 if (function_exists($function)) {
83 $ret .= $function($parm);
84 }
85 }
86 }
87
88 /* Variable-length argument lists have a slight problem when */
89 /* passing values by reference. Pity. This is a workaround. */
90 return $ret;
91}
cd7fc9e6 92
93/**
94 * This function checks whether the user's USER_AGENT is known to
95 * be broken. If so, returns true and the plugin is invisible to the
96 * offending browser.
97 */
98function soupNazi(){
99
cd7fc9e6 100 $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
101 'Opera/4', 'OmniWeb', 'Lynx');
961ca3d8 102 sqgetGlobalVar('HTTP_USER_AGENT', $user_agent, SQ_SERVER);
cd7fc9e6 103 foreach($soup_menu as $browser) {
961ca3d8 104 if(stristr($user_agent, $browser)) {
cd7fc9e6 105 return 1;
106 }
107 }
108 return 0;
109}
0606ca1f 110/*************************************/
111/*** MAIN PLUGIN LOADING CODE HERE ***/
112/*************************************/
113
114/* On startup, register all plugins configured for use. */
115if (isset($plugins) && is_array($plugins)) {
116 foreach ($plugins as $name) {
117 use_plugin($name);
2d367c68 118 }
0606ca1f 119}
076c01d7 120
b68edc75 121?>