load_hooks(); return $this->run_hook($name,$data); } /* * charge l'ensemble des hooks disponibles * pas de gestion de cache, on charge tout à l'invocation */ private function load_hooks() { $numargs = func_num_args(); if ($numargs <> 0) return false; $args = func_get_args(); if (!is_dir($this->dir_hook)) return false; foreach(scandir($this->dir_hook) as $file) { if ($file === '.' || $file === '..') continue; $this->plugins[] = basename($file,'.php'); include($this->dir_hook.$file); } } /* * charge l'ensemble des fonctions disponible pour un hook donné */ private function run_hook() { $output = ''; $numargs = func_num_args(); if ($numargs <> 2) return false; $args = func_get_args(); $hook = $args[0]; foreach($this->plugins as $plugin) { if (function_exists($plugin."_".$hook)) $output .= call_user_func_array($plugin."_".$hook,array($args[1])); } return $output; } } /* Class hooks */ ?>