8 function __construct() {
9 $this->ircmain
= main
::GetInstance();
12 public function load_plugin($plugin_name) {
13 if ( !array_key_exists ( $plugin_name, $this->plugin_list
) ) {
14 if ( is_readable('./plugins/'.$plugin_name.'-plugin.inc.php') ) {
15 require_once './plugins/'.$plugin_name.'-plugin.inc.php';
16 $this->plugin_list
[$plugin_name] = new $plugin_name($this);
17 self
::plugin_register_cmd($plugin_name, $this->plugin_list
[$plugin_name]->commands_list());
19 throw new Exception("Class '$plugin_name' not found",0);
24 protected function plugin_register_cmd($plugin,$commands) {
25 foreach ($commands as $method => $info) {
26 if (!method_exists($this->plugin_list
[$plugin],$method) ||
!is_callable(array($this->plugin_list
[$plugin],$method))) {
27 trigger_error("method '$plugin:$method' in the commands list is not callable.\n",E_USER_WARNING
);
29 self
::add_command($plugin,$method,$info['accepted_args'],$info['help'],$info['type']);
34 public function unload_plugin($plugin_name) {
35 if ( array_key_exists ( $plugin_name, $this->plugin_list
) ) {
36 unset( $this->plugin_list
[$plugin_name] );
40 private function do_command ($msg_info,$plugin,$method) {
41 $all_args = array_slice(func_get_args(), 3);
43 if (isset($this->commands
[$plugin])) {
44 foreach ($this->commands
[$plugin] as $method_name => $methods) {
45 if ($method_name == $method) {
46 $accepted_args = $methods['accepted_args'];
48 if ( $accepted_args >= 1 )
49 $the_args = array_slice($all_args, 0, $accepted_args);
50 elseif ( $accepted_args == 0 )
53 $the_args = $all_args;
56 // print_r($the_args);
59 if ($plugin == 'core') {
60 call_user_func_array(array($this->ircmain
,$method_name),$the_args);
62 $this->plugin_list
[$plugin]->current_message($msg_info);
63 call_user_func_array(array($this->plugin_list
[$plugin],$method_name),$the_args);
70 private function add_command($plugin,$method_to_add,$accepted_args=0,$help='',$type='public') {
71 if (isset($this->commands
[$plugin][$method_to_add])) {
75 $this->commands
[$plugin][$method_to_add] = array(
76 'accepted_args' => $accepted_args,
83 private function remove_command($plugin,$method_to_remove) {
84 if ($method_to_remove == '_all_method') {
85 unset($this->commands
[$plugin]);
86 } elseif (isset($this->commands
[$plugin][$method_to_remove])) {
87 unset($this->commands
[$plugin][$method_to_remove]);
89 $this->commands
[$plugin] = $new_method_list;
94 private function list_command($plugin) {
95 if (isset($this->commands
[$plugin])) {
96 foreach ($this->commands
[$plugin] as $method_name => $method_info) {
97 $command_list[] = array_merge(array('method'=>$method_name),$method_info);