-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport.php
82 lines (77 loc) · 2.64 KB
/
import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* import.php , import managing
*
* This file implements module loading and unloading using the module
* managing system.
*
* Copyright 2008 sebbu <[email protected]>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author sebbu <[email protected]>
* @package CFlxBotServer
*/
//start_of_import
function import($where, $who, $module) {
$module=trim($module);
if( $GLOBALS['first_time_import'] ) {
//we set up some variables
$GLOBALS['modules'] = array();
$GLOBALS['first_time_import'] = false;
}
if( !preg_match( '#^[a-zA-Z0-9_-]+$#', $module ) ) {
echo 'Uncorrect module.<br/>' . "\r\n";
return false;
}
if(array_key_exists($module,$GLOBALS['modules'])) {
echo 'Module already loaded.<br/>'."\r\n";
return false;
}
$file = 'import/' . $module . '.php';
if( !file_exists( $file ) ) {
echo 'Unexistant module.<br/>' . "\r\n";
return false;
}
$GLOBALS['modules'][$module] = array( 'functions'=>array(), 'variables'=>array(), 'used_by'=>array() );
$GLOBALS['modules'][$module]['functions'][$module . '_load'] = get_module_function( $module . '_load', $file, $module );
$GLOBALS['modules'][$module]['functions'][$module . '_unload'] = get_module_function( $module . '_unload', $file, $module );
//var_dump($module);
$GLOBALS['modules'][$module]['functions'][$module . '_load']( $where, $who );
return true;
}
//end_of_import
//start_of_unload
function unload($where, $who, $module) {
$module=trim($module);
if( !preg_match( '#^[a-zA-Z0-9_-]+$#', $module ) ) {
echo 'Uncorrect module.<br/>' . "\r\n";
return false;
}
if(!array_key_exists($module,$GLOBALS['modules'])) {
echo 'Module not loaded.<br/>'."\r\n";
return false;
}
// not needed for allowing unloading deleted module
/*if( !file_exists( 'import/' . $module . '.php' ) ) {
echo 'Unexistant module.<br/>' . "\r\n";
return false;
}*/
// call module unload
if(count($GLOBALS['modules'][$module]['used_by'])>0) {
if(array_key_exists('oServer',$GLOBALS)) {
say($where,$who,'Déchargement du module impossible car il est encore utilisé par les modules suivant : '.
implode(' ',array_keys($GLOBALS['modules'][$module]['used_by'])));
}
else {
echo 'Déchargement du module impossible car il est encore utilisé par les modules suivant : '.
implode(' ',array_keys($GLOBALS['modules'][$module]['used_by'])).'<br/><br/>'."\r\n\r\n";
}
return false;
}
$GLOBALS['modules'][$module]['functions'][$module . '_unload']( $where, $who );
return true;
}
//end_of_unload
?>