From e1ceb050e19c7574bca146a8da7047ee4ff456b5 Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Sun, 10 Jul 2016 05:02:35 -0400
Subject: [PATCH] Merge branch 'stable-3.1'
---
interface/lib/classes/plugin.inc.php | 39 ++++++++++++++++++++++++++-------------
1 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/interface/lib/classes/plugin.inc.php b/interface/lib/classes/plugin.inc.php
index 1992457..8a8ac20 100644
--- a/interface/lib/classes/plugin.inc.php
+++ b/interface/lib/classes/plugin.inc.php
@@ -45,12 +45,12 @@
if(isset($_SESSION['s']['plugin_cache'])) unset($_SESSION['s']['plugin_cache']);
$plugin_dirs = array();
- $plugin_dirs[] = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV;
+ $plugin_dirs[] = ISPC_LIB_PATH.FS_DIV.'plugins';
if(is_dir(ISPC_WEB_PATH)) {
if($dh = opendir(ISPC_WEB_PATH)) {
while(($file = readdir($dh)) !== false) {
- if($file !== '.' && $file !== '..' && is_dir($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';
+ 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';
}
closedir($dh);
}
@@ -63,6 +63,7 @@
$plugins_dir = $plugin_dirs[$d];
if (is_dir($plugins_dir)) {
if ($dh = opendir($plugins_dir)) {
+ $tmp_plugins = array();
//** Go trough all files in the plugin dir
while (($file = readdir($dh)) !== false) {
if($file !== '.' && $file !== '..' && substr($file, -8, 8) == '.inc.php') {
@@ -76,7 +77,7 @@
//** load the plugins
foreach($tmp_plugins as $plugin_name => $file) {
- include_once $plugins_dir.$file;
+ require $plugins_dir . FS_DIV . $file;
if($this->debug) $app->log('Loading plugin: '.$plugin_name, LOGLEVEL_DEBUG);
$app->loaded_plugins[$plugin_name] = new $plugin_name;
$app->loaded_plugins[$plugin_name]->onLoad();
@@ -107,28 +108,33 @@
This function is called when a certian action occurs, e.g. a form gets saved or a user is logged in.
*/
- public function raiseEvent($event_name, $data) {
+ public function raiseEvent($event_name, $data, $return_data = false) {
global $app;
if(!isset($_SESSION['s']['plugin_cache'])) {
$this->loadPluginCache();
if($this->debug) $app->log('Loaded the plugin cache.', LOGLEVEL_DEBUG);
}
-
-
+
+ $result = '';
$sub_events = explode(':', $event_name);
if(is_array($sub_events)) {
if(count($sub_events) == 3) {
$tmp_event = $sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
- $this->callPluginEvent($tmp_event, $data);
+ $tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
+ if($return_data == true && $tmpresult) $result .= $tmpresult;
+
$tmp_event = $sub_events[0].':'.$sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
- $this->callPluginEvent($tmp_event, $data);
+ $tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
+ if($return_data == true && $tmpresult) $result .= $tmpresult;
+
$tmp_event = $sub_events[0].':'.$sub_events[1].':'.$sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
- $this->callPluginEvent($tmp_event, $data);
+ $tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
+ if($return_data == true && $tmpresult) $result .= $tmpresult;
/*$sub_events = array_reverse($sub_events);
$tmp_event = '';
@@ -140,15 +146,20 @@
*/
} else {
if($this->debug) $app->log("Called Event '$sub_events[0]'", LOGLEVEL_DEBUG);
- $this->callPluginEvent($sub_events[0], $data);
+ $tmpresult = $this->callPluginEvent($sub_events[0], $data, $return_data);
+ if($return_data == true && $tmpresult) $result .= $tmpresult;
}
}
+
+ if($return_data == true) return $result;
} // end function raiseEvent
//* Internal function to load the plugin and call the event function in the plugin.
- private function callPluginEvent($event_name, $data) {
+ private function callPluginEvent($event_name, $data, $return_data = false) {
global $app;
+
+ $result = '';
//* execute the functions for the events
if(@is_array($_SESSION['s']['plugin_cache'][$event_name])) {
@@ -175,12 +186,14 @@
if($this->debug) $app->log("Called method: '$function_name' in plugin '$plugin_name' for event '$event_name'", LOGLEVEL_DEBUG);
// call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data);
- call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data);
-
+ $tmpresult = call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data);
+ if($return_data == true && $tmpresult) $result .= $tmpresult;
}
}
}
+
+ if($return_data == true) return $result;
} // end functiom callPluginEvent
--
Gitblit v1.9.1