26 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
45 var $_preloads = array();
50 var $_events = array();
57 function XoopsPreload()
68 static function &getInstance()
70 static $instance =
false;
72 $instance =
new XoopsPreload();
82 function setPreloads()
87 foreach ($modules_list as
$module) {
88 if (is_dir(
$dir = XOOPS_ROOT_PATH .
"/modules/{$module}/preloads/")) {
89 $file_list = XoopsLists::getFileListAsArray(
$dir);
90 foreach ($file_list as
$file) {
91 if (preg_match(
'/(\.php)$/i', $file)) {
92 $file = substr($file, 0, -4);
94 $this->_preloads[
$i][
'file'] =
$file;
110 foreach ($this->_preloads as $preload) {
111 include_once XOOPS_ROOT_PATH .
'/modules/' . $preload[
'module'] .
'/preloads/' . $preload[
'file'].
'.php';
112 $class_name = ucfirst($preload[
'module']) . ucfirst($preload[
'file']) .
'Preload' ;
113 if (!class_exists($class_name)) {
116 $class_methods = get_class_methods($class_name);
117 foreach ($class_methods as
$method) {
118 if (strpos($method,
'event') === 0) {
119 $event_name = strtolower(str_replace(
'event',
'', $method));
120 $event= array(
'class_name' => $class_name,
'method' => $method);
121 $this->_events[$event_name][] = $event;
135 function triggerEvent($event_name, $args = array())
137 $event_name = strtolower(str_replace(
'.',
'', $event_name));
138 if (isset($this->_events[$event_name])) {
139 foreach ($this->_events[$event_name] as $event) {
140 call_user_func(array($event[
'class_name'], $event[
'method']), $args);