Esempio n. 1
0
 /**
  * load all active plugins
  *
  * @param string $dir
  */
 public static function loadPlugins($dir)
 {
     $dh = opendir($dir);
     if ($dh === false) {
         return;
     }
     $excludeDirs = array('.', '..');
     while (($file = readdir($dh)) !== false) {
         if (in_array($file, $excludeDirs)) {
             continue;
         }
         $configFile = $dir . DIRECTORY_SEPARATOR . $file . DIRECTORY_SEPARATOR . 'config.ini';
         if (file_exists($configFile)) {
             $config = parse_ini_file($configFile);
             $pluginName = isset($config['name']) ? $config['name'] : '';
             if (SJB_Users_CookiePreferences::isPluginDisabled($pluginName)) {
                 continue;
             }
             $active = isset($config['active']) && $config['active'] == '1';
             $initFile = isset($config['init_file']) ? $config['init_file'] : '';
             $config['config_file'] = $configFile;
             $config['group_id'] = isset($config['group']) ? str_replace(' ', '_', $config['group']) : '';
             // add to plugins list
             self::$pluginsList[$config['name']] = $config;
             if ($active && !empty($initFile)) {
                 $initFilePath = $dir . DIRECTORY_SEPARATOR . $file . DIRECTORY_SEPARATOR . $initFile;
                 if (file_exists($initFilePath)) {
                     require_once $initFilePath;
                     self::$pluginsLoaded[] = $config;
                 } else {
                     SJB_System::$pluginsErrors[] = "'{$pluginName}' plugin '{$initFilePath}' init file not exists or not readable!";
                 }
             }
         }
     }
     closedir($dh);
 }