@@ -43,35 +43,51 @@ private function loadPluginCache() {
4343
4444
4545 if (isset ($ _SESSION ['s ' ]['plugin_cache ' ])) unset($ _SESSION ['s ' ]['plugin_cache ' ]);
46-
47- $ plugins_dir = ISPC_LIB_PATH .FS_DIV .'plugins ' .FS_DIV ;
46+
47+ $ plugin_dirs = array ();
48+ $ plugin_dirs [] = ISPC_LIB_PATH .FS_DIV .'plugins ' ;
49+
50+ if (is_dir (ISPC_WEB_PATH )) {
51+ if ($ dh = opendir (ISPC_WEB_PATH )) {
52+ while (($ file = readdir ($ dh )) !== false ) {
53+ if ($ file !== '. ' && $ file !== '.. ' && is_dir (ISPC_WEB_PATH . FS_DIV . $ file ) && is_dir (ISPC_WEB_PATH . FS_DIV . $ file . FS_DIV . 'lib ' . FS_DIV . 'plugin.d ' )) $ plugin_dirs [] = ISPC_WEB_PATH . FS_DIV . $ file . FS_DIV . 'lib ' . FS_DIV . 'plugin.d ' ;
54+ }
55+ closedir ($ dh );
56+ }
57+ }
58+
4859 $ _SESSION ['s ' ]['plugin_cache ' ] = array ();
4960 $ tmp_plugins = array ();
50-
51- if (is_dir ($ plugins_dir )) {
52- if ($ dh = opendir ($ plugins_dir )) {
53- //** Go trough all files in the plugin dir
54- while (($ file = readdir ($ dh )) !== false ) {
55- if ($ file != '. ' && $ file != '.. ' && substr ($ file , -8 , 8 ) == '.inc.php ' ) {
56- $ plugin_name = substr ($ file , 0 , -8 );
57- $ tmp_plugins [$ plugin_name ] = $ file ;
61+
62+ for ($ d = 0 ; $ d < count ($ plugin_dirs ); $ d ++) {
63+ $ plugins_dir = $ plugin_dirs [$ d ];
64+ if (is_dir ($ plugins_dir )) {
65+ if ($ dh = opendir ($ plugins_dir )) {
66+ $ tmp_plugins = array ();
67+ //** Go trough all files in the plugin dir
68+ while (($ file = readdir ($ dh )) !== false ) {
69+ if ($ file !== '. ' && $ file !== '.. ' && substr ($ file , -8 , 8 ) == '.inc.php ' ) {
70+ $ plugin_name = substr ($ file , 0 , -8 );
71+ $ tmp_plugins [$ plugin_name ] = $ file ;
72+ }
5873 }
59- }
60- //** sort the plugins by name
61- ksort ($ tmp_plugins );
62-
63- //** load the plugins
64- foreach ($ tmp_plugins as $ plugin_name => $ file ) {
65- include_once $ plugins_dir .$ file ;
66- if ($ this ->debug ) $ app ->log ('Loading plugin: ' .$ plugin_name , LOGLEVEL_DEBUG );
67- $ app ->loaded_plugins [$ plugin_name ] = new $ plugin_name ;
68- $ app ->loaded_plugins [$ plugin_name ]->onLoad ();
74+ closedir ($ dh );
75+ //** sort the plugins by name
76+ ksort ($ tmp_plugins );
77+
78+ //** load the plugins
79+ foreach ($ tmp_plugins as $ plugin_name => $ file ) {
80+ require $ plugins_dir . FS_DIV . $ file ;
81+ if ($ this ->debug ) $ app ->log ('Loading plugin: ' .$ plugin_name , LOGLEVEL_DEBUG );
82+ $ app ->loaded_plugins [$ plugin_name ] = new $ plugin_name ;
83+ $ app ->loaded_plugins [$ plugin_name ]->onLoad ();
84+ }
85+ } else {
86+ $ app ->log ('Unable to open the plugins directory: ' .$ plugins_dir , LOGLEVEL_ERROR );
6987 }
7088 } else {
71- $ app ->log ('Unable to open the plugins directory: ' .$ plugins_dir , LOGLEVEL_ERROR );
89+ $ app ->log ('Plugins directory missing : ' .$ plugins_dir , LOGLEVEL_ERROR );
7290 }
73- } else {
74- $ app ->log ('Plugins directory missing: ' .$ plugins_dir , LOGLEVEL_ERROR );
7591 }
7692
7793 }
@@ -81,39 +97,44 @@ private function loadPluginCache() {
8197 for faster lookups without the need to load all plugins for every page.
8298 */
8399
84- public function registerEvent ($ event_name , $ plugin_name , $ function_name ) {
100+ public function registerEvent ($ event_name , $ plugin_name , $ function_name, $ module_name = '' ) {
85101 global $ app ;
86102
87- $ _SESSION ['s ' ]['plugin_cache ' ][$ event_name ][] = array ('plugin ' => $ plugin_name , 'function ' => $ function_name );
103+ $ _SESSION ['s ' ]['plugin_cache ' ][$ event_name ][] = array ('plugin ' => $ plugin_name , 'function ' => $ function_name, ' module ' => $ module_name );
88104 if ($ this ->debug ) $ app ->log ("Plugin ' $ plugin_name' has registered the function ' $ function_name' for the event ' $ event_name' " , LOGLEVEL_DEBUG );
89105 }
90106
91107 /*
92108 This function is called when a certian action occurs, e.g. a form gets saved or a user is logged in.
93109 */
94110
95- public function raiseEvent ($ event_name , $ data ) {
111+ public function raiseEvent ($ event_name , $ data, $ return_data = false ) {
96112 global $ app ;
97113
98114 if (!isset ($ _SESSION ['s ' ]['plugin_cache ' ])) {
99115 $ this ->loadPluginCache ();
100116 if ($ this ->debug ) $ app ->log ('Loaded the plugin cache. ' , LOGLEVEL_DEBUG );
101117 }
102-
103-
118+
119+ $ result = '' ;
104120 $ sub_events = explode (': ' , $ event_name );
105121
106122 if (is_array ($ sub_events )) {
107123 if (count ($ sub_events ) == 3 ) {
108124 $ tmp_event = $ sub_events [2 ];
109125 if ($ this ->debug ) $ app ->log ("Called Event ' $ tmp_event' " , LOGLEVEL_DEBUG );
110- $ this ->callPluginEvent ($ tmp_event , $ data );
126+ $ tmpresult = $ this ->callPluginEvent ($ tmp_event , $ data , $ return_data );
127+ if ($ return_data == true && $ tmpresult ) $ result .= $ tmpresult ;
128+
111129 $ tmp_event = $ sub_events [0 ].': ' .$ sub_events [2 ];
112130 if ($ this ->debug ) $ app ->log ("Called Event ' $ tmp_event' " , LOGLEVEL_DEBUG );
113- $ this ->callPluginEvent ($ tmp_event , $ data );
131+ $ tmpresult = $ this ->callPluginEvent ($ tmp_event , $ data , $ return_data );
132+ if ($ return_data == true && $ tmpresult ) $ result .= $ tmpresult ;
133+
114134 $ tmp_event = $ sub_events [0 ].': ' .$ sub_events [1 ].': ' .$ sub_events [2 ];
115135 if ($ this ->debug ) $ app ->log ("Called Event ' $ tmp_event' " , LOGLEVEL_DEBUG );
116- $ this ->callPluginEvent ($ tmp_event , $ data );
136+ $ tmpresult = $ this ->callPluginEvent ($ tmp_event , $ data , $ return_data );
137+ if ($ return_data == true && $ tmpresult ) $ result .= $ tmpresult ;
117138
118139 /*$sub_events = array_reverse($sub_events);
119140 $tmp_event = '';
@@ -125,23 +146,36 @@ public function raiseEvent($event_name, $data) {
125146 */
126147 } else {
127148 if ($ this ->debug ) $ app ->log ("Called Event ' $ sub_events [0 ]' " , LOGLEVEL_DEBUG );
128- $ this ->callPluginEvent ($ sub_events [0 ], $ data );
149+ $ tmpresult = $ this ->callPluginEvent ($ sub_events [0 ], $ data , $ return_data );
150+ if ($ return_data == true && $ tmpresult ) $ result .= $ tmpresult ;
129151 }
130152 }
153+
154+ if ($ return_data == true ) return $ result ;
131155
132156 } // end function raiseEvent
133157
134158 //* Internal function to load the plugin and call the event function in the plugin.
135- private function callPluginEvent ($ event_name , $ data ) {
159+ private function callPluginEvent ($ event_name , $ data, $ return_data = false ) {
136160 global $ app ;
137161
162+ $ result = '' ;
163+
138164 //* execute the functions for the events
139165 if (@is_array ($ _SESSION ['s ' ]['plugin_cache ' ][$ event_name ])) {
140166 foreach ($ _SESSION ['s ' ]['plugin_cache ' ][$ event_name ] as $ rec ) {
141167 $ plugin_name = $ rec ['plugin ' ];
142168 $ function_name = $ rec ['function ' ];
143- $ plugin_file = ISPC_LIB_PATH .FS_DIV .'plugins ' .FS_DIV .$ plugin_name .'.inc.php ' ;
144-
169+ $ module_name = $ rec ['module ' ];
170+ if ($ module_name != '' ) {
171+ if (strpos ($ module_name , '.. ' ) !== false || strpos ($ module_name , '/ ' ) !== false ) {
172+ if ($ this ->debug ) $ app ->log ('Module name ' . $ module_name . ' contains illegal characters. ' , LOGLEVEL_DEBUG );
173+ continue ;
174+ }
175+ $ plugin_file = ISPC_WEB_PATH . FS_DIV . $ module_name . FS_DIV . 'lib ' . FS_DIV . 'plugin.d ' . FS_DIV . $ plugin_name . '.inc.php ' ;
176+ } else {
177+ $ plugin_file = ISPC_LIB_PATH . FS_DIV . 'plugins ' . FS_DIV . $ plugin_name . '.inc.php ' ;
178+ }
145179
146180 if (is_file ($ plugin_file )) {
147181 if (!isset ($ app ->loaded_plugins [$ plugin_name ])) {
@@ -152,12 +186,14 @@ private function callPluginEvent($event_name, $data) {
152186 if ($ this ->debug ) $ app ->log ("Called method: ' $ function_name' in plugin ' $ plugin_name' for event ' $ event_name' " , LOGLEVEL_DEBUG );
153187 // call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data);
154188
155- call_user_func (array ($ app ->loaded_plugins [$ plugin_name ], $ function_name ), $ event_name , $ data );
156-
189+ $ tmpresult = call_user_func (array ($ app ->loaded_plugins [$ plugin_name ], $ function_name ), $ event_name , $ data );
190+ if ( $ return_data == true && $ tmpresult ) $ result .= $ tmpresult ;
157191 }
158192 }
159193
160194 }
195+
196+ if ($ return_data == true ) return $ result ;
161197
162198 } // end functiom callPluginEvent
163199
0 commit comments