1+ <?php
2+
3+ /*
4+ Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+ All rights reserved.
6+
7+ Redistribution and use in source and binary forms, with or without modification,
8+ are permitted provided that the following conditions are met:
9+
10+ * Redistributions of source code must retain the above copyright notice,
11+ this list of conditions and the following disclaimer.
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+ * Neither the name of ISPConfig nor the names of its contributors
16+ may be used to endorse or promote products derived from this software without
17+ specific prior written permission.
18+
19+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+ */
30+
31+ class plugins {
32+
33+ var $ notification_events = array ();
34+
35+ /*
36+ This function is called to load the plugins from the plugins-available folder
37+ */
38+
39+ function loadPlugins () {
40+ global $ app ,$ conf ;
41+
42+ $ plugins_dir = $ conf ["rootpath " ].$ conf ["fs_div " ]."lib " .$ conf ["fs_div " ]."plugins-enabled " .$ conf ["fs_div " ]
43+
44+ if (is_dir ($ plugins_dir )) {
45+ if ($ dh = opendir ($ dir )) {
46+ while (($ file = readdir ($ dh )) !== false ) {
47+ if ($ file != '. ' && $ file != '.. ' ) {
48+ $ plugin_name = substr ($ file ,0 ,-8 );
49+ include_once ($ plugins_dir .$ file );
50+ $ app ->log ("Loading Plugin: $ plugin_name " ,LOGLEVEL_DEBUG );
51+ $ app ->plugins [$ plugin_name ] = new $ module_name ;
52+ $ app ->plugins [$ plugin_name ]->onLoad ();
53+ }
54+ }
55+ }
56+ } else {
57+ $ app ->log ("Plugin directory missing: $ plugins_dir " ,LOGLEVEL_ERROR );
58+ }
59+
60+ }
61+
62+ /*
63+ This function is called by the modules to register for a specific
64+ table change notification
65+ */
66+
67+ function registerEvent ($ event_name ,$ plugin_name ,$ function_name ) {
68+ $ this ->notification_events [$ event_name ][] = array ('plugin ' => $ plugin_name , 'function ' => $ function_name );
69+ }
70+
71+
72+ function raiseEvent ($ event_name ,$ data ) {
73+ global $ app ;
74+
75+ // Get the hooks for this table
76+ $ events = $ this ->notification_hevents [$ event_name ];
77+
78+ if (is_array ($ events )) {
79+ foreach ($ events as $ event ) {
80+ $ plugin_name = $ event ["plugin " ];
81+ $ function_name = $ event ["function " ];
82+ // Claa the processing function of the module
83+ call_user_method ($ function_name ,$ app ->plugins [$ plugin_name ],$ event_name ,$ data );
84+ unset($ plugin_name );
85+ unset($ function_name );
86+ }
87+ }
88+ unset($ event );
89+ unset($ events );
90+ }
91+
92+ }
93+
94+ ?>
0 commit comments