Marius Burkard
2015-12-14 5ddadd99515d0f7568dd1d1d64b4f8f08636cd97
interface/lib/classes/plugin.inc.php
@@ -43,35 +43,50 @@
      if(isset($_SESSION['s']['plugin_cache'])) unset($_SESSION['s']['plugin_cache']);
      $plugins_dir = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV;
      $plugin_dirs = array();
      $plugin_dirs[] = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV;
      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';
            }
            closedir($dh);
         }
      }
      $_SESSION['s']['plugin_cache'] = array();
      $tmp_plugins = array();
      if (is_dir($plugins_dir)) {
         if ($dh = opendir($plugins_dir)) {
            //** Go trough all files in the plugin dir
            while (($file = readdir($dh)) !== false) {
               if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
                  $plugin_name = substr($file, 0, -8);
                  $tmp_plugins[$plugin_name] = $file;
      for($d = 0; $d < count($plugin_dirs); $d++) {
         $plugins_dir = $plugin_dirs[$d];
         if (is_dir($plugins_dir)) {
            if ($dh = opendir($plugins_dir)) {
               //** Go trough all files in the plugin dir
               while (($file = readdir($dh)) !== false) {
                  if($file !== '.' && $file !== '..' && substr($file, -8, 8) == '.inc.php') {
                     $plugin_name = substr($file, 0, -8);
                     $tmp_plugins[$plugin_name] = $file;
                  }
               }
            }
            //** sort the plugins by name
            ksort($tmp_plugins);
               closedir($dh);
               //** sort the plugins by name
               ksort($tmp_plugins);
            //** load the plugins
            foreach($tmp_plugins as $plugin_name => $file) {
               include_once $plugins_dir.$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();
               //** load the plugins
               foreach($tmp_plugins as $plugin_name => $file) {
                  include_once $plugins_dir.$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();
               }
            } else {
               $app->log('Unable to open the plugins directory: '.$plugins_dir, LOGLEVEL_ERROR);
            }
         } else {
            $app->log('Unable to open the plugins directory: '.$plugins_dir, LOGLEVEL_ERROR);
            $app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR);
         }
      } else {
         $app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR);
      }
   }
@@ -81,10 +96,10 @@
    for faster lookups without the need to load all plugins for every page.
   */
   public function registerEvent($event_name, $plugin_name, $function_name) {
   public function registerEvent($event_name, $plugin_name, $function_name, $module_name = '') {
      global $app;
      $_SESSION['s']['plugin_cache'][$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name);
      $_SESSION['s']['plugin_cache'][$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name, 'module' => $module_name);
      if($this->debug) $app->log("Plugin '$plugin_name' has registered the function '$function_name' for the event '$event_name'", LOGLEVEL_DEBUG);
   }
@@ -140,8 +155,16 @@
         foreach($_SESSION['s']['plugin_cache'][$event_name] as $rec) {
            $plugin_name = $rec['plugin'];
            $function_name = $rec['function'];
            $plugin_file = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV.$plugin_name.'.inc.php';
            $module_name = $rec['module'];
            if($module_name != '') {
               if(strpos($module_name, '..') !== false || strpos($module_name, '/') !== false) {
                  if($this->debug) $app->log('Module name ' . $module_name . ' contains illegal characters.', LOGLEVEL_DEBUG);
                  continue;
               }
               $plugin_file = ISPC_WEB_PATH . FS_DIV . $module_name . FS_DIV . 'lib' . FS_DIV . 'plugin.d' . FS_DIV . $plugin_name . '.inc.php';
            } else {
               $plugin_file = ISPC_LIB_PATH . FS_DIV . 'plugins' . FS_DIV . $plugin_name . '.inc.php';
            }
            if(is_file($plugin_file)) {
               if(!isset($app->loaded_plugins[$plugin_name])) {