Skip to content

Commit 62a1108

Browse files
committed
Added plugin class for the server daemon and renamed the modules class.
1 parent 5f0f02a commit 62a1108

File tree

5 files changed

+125
-6
lines changed

5 files changed

+125
-6
lines changed

server/lib/app.inc.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
*/
2929

3030
class app {
31-
32-
function app() {
31+
32+
var modules = array();
33+
var plugins = array();
34+
35+
function app() {
3336

3437
global $conf;
3538

@@ -104,7 +107,7 @@ function log($msg, $priority = 0) {
104107
fclose($fp);
105108

106109
} else {
107-
$this->error("Logfile ist nicht beschreibbar.");
110+
$this->error("Unable to write to logfile.");
108111
}
109112
} // if
110113
} // func

server/lib/classes/modules.inc.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,25 @@ class modules {
3737
*/
3838

3939
function loadModules() {
40-
global $app;
40+
global $app, $conf;
41+
42+
$modules_dir = $conf["rootpath"].$conf["fs_div"]."lib".$conf["fs_div"]."mods-enabled".$conf["fs_div"]
4143

44+
if (is_dir($modules_dir)) {
45+
if ($dh = opendir($dir)) {
46+
while (($file = readdir($dh)) !== false) {
47+
if($file != '.' && $file != '..') {
48+
$module_name = substr($file,0,-8);
49+
include_once($modules_dir.$file);
50+
$app->log("Loading Module: $module_name",LOGLEVEL_DEBUG);
51+
$app->modules[$module_name] = new $module_name;
52+
$app->modules[$module_name]->onLoad();
53+
}
54+
}
55+
}
56+
} else {
57+
$app->log("Modules directory missing: $modules_dir",LOGLEVEL_ERROR);
58+
}
4259
}
4360

4461
/*
@@ -79,7 +96,7 @@ function raiseTableHook($table_name,$action,$data) {
7996
$module_name = $hook["module"];
8097
$function_name = $hook["function"];
8198
// Claa the processing function of the module
82-
call_user_method($function_name,$app->$module_name,$table_name,$action,$data);
99+
call_user_method($function_name,$app->modules[$module_name],$table_name,$action,$data);
83100
unset($module_name);
84101
unset($function_name);
85102
}

server/lib/classes/plugins.inc.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
?>

server/lib/config.inc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@
6666
$conf["load_server_config"] = true;
6767

6868

69+
70+
define("LOGLEVEL_DEBUG",0);
71+
define("LOGLEVEL_WARN",1);
72+
define("LOGLEVEL_ERROR",2);
73+
6974
?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class mail_module {
3232

33-
var $module_name = 'mail';
33+
var $module_name = 'mail_module';
3434
var $class_name = 'mail_module';
3535
var $actions_available = array( 'mail_domain_insert',
3636
'mail_domain_update',

0 commit comments

Comments
 (0)