-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.class.php
More file actions
151 lines (142 loc) · 3.47 KB
/
Copy pathmodules.class.php
File metadata and controls
151 lines (142 loc) · 3.47 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
class modules
{
public $core;
public $module_list;
public $event_list;
public function __construct(&$core)
{
$this->core = &$core;
$this->module_list = array();
$this->event_list = array();
}
public function generateModHash($module_name)
{
$ret = "42";
$ret = $module_name."&&&".microtime();
$ret = sha1($ret).time();
$ret = "mod_".str_rot13(md5($ret))."__".$module_name;
if(isset($this->module_list[$ret]))
{
return $this->generateModHash("$$".$module_name);
}
else
{
return $ret;
}
}
public function unloadModule($module_name)
{
// lets find the module_id first
foreach($this->module_list as $module_id => $module)
{
if($module->module_name == $module_name)
{
break;
}
}
echo $module_id."\n";
if($this->module_list[$module_id]->module_name == $module_name)
{
$events = 0;
foreach($this->event_list as $key => $event)
{
if($event->module_id == $module_id)
{
unset($this->event_list[$key]);
$events++;
}
}
echo "DELETED $events EVENTS!\n";
unset($this->module_list[$module_id]);
if($this->core->online == true)
{
$this->core->privmsg($this->core->config->owner,"admin: deleted $events events! unloaded module $module_name!");
}
}
else
{
echo "MODULE NOT LOADED\n";
if($this->core->online == true)
{
$this->core->privmsg($this->core->config->owner,"admin: module $module_name not loaded!");
}
}
}
public function loadModule($module_name)
{
$module_loaded = false;
foreach($this->module_list as $module)
{
if($module_name == $module->module_name)
{
$module_loaded = true;
}
}
if($module_loaded == false)
{
echo "LOAD_MODULE: $module_name (";
if(file_exists("modules/".$module_name.".php"))
{
$mod_hash = $this->generateModHash($module_name);
echo "$mod_hash)\n";
$content = file_get_contents("modules/".$module_name.".php");
$content = strtr($content,array('<?php' => '','?>' => '','/*MODULE_ID*/' => $mod_hash));
eval($content);
$mod = new $mod_hash($this->core);
$this->module_list[$mod_hash] = (object) array(
"module_name" => $module_name,
"module_id" => $mod_hash,
"ref" => &$mod,
);
if($this->core->online == true)
{
$this->core->privmsg($this->core->config->owner,"admin: loaded module $module_name ($mod_hash)");
}
}
else
{
echo "MODULE-FILE NOT FOUND!)\n";
if($this->core->online == true)
{
$this->core->privmsg($this->core->config->owner,"admin: wanted to load ".$module_name.", but can't find the file :(");
}
}
}
else
{
echo "MODULE ALREADY LOADED!)\n";
if($this->core->online == true)
{
$this->core->privmsg($this->core->config->owner,"admin: already loaded module $module_name");
}
}
}
public function registerEvent($event_name,&$ref)
{
if($this->core->online == true)
{
$this->core->privmsg($this->core->config->owner,"admin: register event $event_name");
}
$this->event_list[] = (object) array (
//"ref" => &$ref,
"event_name" => $event_name,
"module_id" => $ref->module_id,
);
}
public function callEvent($event_name,$event_data=array())
{
//$this->core->privmsg($this->core->config->owner,"admin: call event $event_name");
foreach($this->event_list as $event)
{
if($event->event_name == $event_name)
{
if(isset($this->module_list[$event->module_id]))
{
$this->module_list[$event->module_id]->ref->$event_name($event_data);
}
}
}
}
}
?>