function update_mini_modules_list($update_cache = true)
 {
     global $Sql, $MODULES;
     $installed_minimodules = array();
     $query = "SELECT id, title FROM " . DB_TABLE_MENUS . " WHERE class='" . strtolower(MODULE_MINI_MENU__CLASS) . "'";
     $modules = array();
     foreach ($MODULES as $module_id => $module) {
         if (!empty($module['activ']) && $module['activ'] == 1) {
             $modules[] = $module_id;
         }
     }
     $result = $Sql->query_while($query . ";", __LINE__, __FILE__);
     while ($row = $Sql->fetch_assoc($result)) {
         $title = explode('/', strtolower($row['title']), 2);
         if (!is_array($title) || count($title) < 1) {
             continue;
         }
         $module = $title[0];
         if (in_array($module, $modules)) {
             $installed_minimodules[] = $module;
         } else {
             MenuService::delete($row['id']);
         }
     }
     $Sql->query_close($result);
     $new_modules = array_diff($modules, $installed_minimodules);
     foreach ($new_modules as $module) {
         MenuService::add_mini_module($module, false);
     }
     if ($update_cache) {
         MenuService::generate_cache();
     }
 }
 /**
  * @static
  * @desc Installs a module.
  * @param string $module_identifier Module identifier (name of its folder)
  * @param bool $enable_module true if you want the module to be enabled, otherwise false.
  * @return int One of the following error codes:
  * <ul>
  * 	<li>MODULE_INSTALLED: the installation succeded</li>
  * 	<li>MODULE_ALREADY_INSTALLED: the module is already installed</li>
  * 	<li>UNEXISTING_MODULE: the module you want to install doesn't exist</li>
  * 	<li>PHP_VERSION_CONFLICT: the server PHP version is two old to be able to run the module code (config set in the config.ini module file)</li>
  * 	<li>CONFIG_CONFLICT: the configuration field is already used</i>
  * </ul>
  */
 public static function install_module($module_identifier, $enable_module = true, $generate_cache = true)
 {
     self::update_class_list();
     if (empty($module_identifier) || !is_dir(PATH_TO_ROOT . '/' . $module_identifier)) {
         return self::UNEXISTING_MODULE;
     }
     if (self::is_module_installed($module_identifier)) {
         return self::MODULE_ALREADY_INSTALLED;
     }
     $module = new Module($module_identifier, $enable_module);
     $configuration = $module->get_configuration();
     $phpversion = ServerConfiguration::get_phpversion();
     if (version_compare($phpversion, $configuration->get_php_version(), 'lt')) {
         return self::PHP_VERSION_CONFLICT;
     }
     $phpboost_version = GeneralConfig::load()->get_phpboost_major_version();
     if (version_compare($phpboost_version, $configuration->get_compatibility(), '>')) {
         return self::PHPBOOST_VERSION_CONFLICT;
     }
     self::execute_module_installation($module_identifier);
     ModulesConfig::load()->add_module($module);
     ModulesConfig::save();
     // TODO Force initialization ExtensionProviderService for PHPBoost installation
     AppContext::init_extension_provider_service();
     MenuService::add_mini_module($module_identifier, $generate_cache);
     if ($generate_cache) {
         MenuService::generate_cache();
         if (ServerEnvironmentConfig::load()->is_url_rewriting_enabled()) {
             HtaccessFileCache::regenerate();
         }
     }
     return self::MODULE_INSTALLED;
 }
 function install_module($module_identifier, $enable_module = true, $generate_cache = GENERATE_CACHE_AFTER_THE_OPERATION)
 {
     global $Cache, $Sql, $CONFIG, $MODULES;
     if (empty($module_identifier) || !is_dir(PATH_TO_ROOT . '/' . $module_identifier)) {
         return UNEXISTING_MODULE;
     }
     $check_module = (int) $Sql->query("SELECT COUNT(*) FROM " . DB_TABLE_MODULES . " WHERE name = '" . strprotect($module_identifier) . "'", __LINE__, __FILE__);
     if ($check_module > 0) {
         return MODULE_ALREADY_INSTALLED;
     }
     $info_module = load_ini_file(PATH_TO_ROOT . '/' . $module_identifier . '/lang/', get_ulang());
     if (empty($info_module)) {
         return UNEXISTING_MODULE;
     }
     if (!empty($info_module['php_version'])) {
         $phpversion = phpversion();
         if (strpos(phpversion(), '-') !== FALSE) {
             $phpversion = substr($phpversion, 0, strpos(phpversion(), '-'));
         }
         if (version_compare($phpversion, $info_module['php_version'], 'lt')) {
             return PHP_VERSION_CONFLICT;
         }
     }
     $dir_db_module = get_ulang();
     $dir = PATH_TO_ROOT . '/' . $module_identifier . '/db';
     if (!is_dir($dir . '/' . $dir_db_module)) {
         import('io/filesystem/folder');
         $db_scripts_folder = new Folder($dir);
         $existing_db_files = $db_scripts_folder->get_folders('`[a-z_-]+`i');
         $dir_db_module = count($existing_db_files) > 0 ? $existing_db_files[0]->get_name() : '';
     }
     $config = get_ini_config(PATH_TO_ROOT . '/' . $module_identifier . '/lang/', get_ulang());
     if (!empty($config)) {
         $check_config = $Sql->query("SELECT COUNT(*) FROM " . DB_TABLE_CONFIGS . " WHERE name = '" . $module_identifier . "'", __LINE__, __FILE__);
         if (empty($check_config)) {
             $Sql->query_inject("INSERT INTO " . DB_TABLE_CONFIGS . " (name, value) VALUES ('" . $module_identifier . "', '" . addslashes($config) . "');", __LINE__, __FILE__);
         } else {
             return CONFIG_CONFLICT;
         }
     }
     $sql_file = PATH_TO_ROOT . '/' . $module_identifier . '/db/' . $dir_db_module . '/' . $module_identifier . '.' . DBTYPE . '.sql';
     if (file_exists($sql_file)) {
         $Sql->parse($sql_file, PREFIX);
     }
     $module_identifier = strprotect($module_identifier);
     import('core/menu_service');
     MenuService::add_mini_module($module_identifier);
     $Sql->query_inject("INSERT INTO " . DB_TABLE_MODULES . " (name, version, auth, activ) VALUES ('" . $module_identifier . "', '" . addslashes($info_module['version']) . "', 'a:4:{s:3:\"r-1\";i:1;s:2:\"r0\";i:1;s:2:\"r1\";i:1;s:2:\"r2\";i:1;}', '" . (int) $enable_module . "')", __LINE__, __FILE__);
     $php_file = PATH_TO_ROOT . '/' . $module_identifier . '/db/' . $dir_db_module . '/' . $module_identifier . '.php';
     if (file_exists($php_file)) {
         if (!DEBUG) {
             @(include_once $php_file);
         } else {
             include_once $php_file;
         }
     }
     if ($generate_cache) {
         $Cache->Generate_file('modules');
         $Cache->load('modules', RELOAD_CACHE);
         $Cache->Generate_file('css');
         MenuService::generate_cache();
         if ($CONFIG['rewrite'] == 1 && !empty($info_module['url_rewrite'])) {
             $Cache->Generate_file('htaccess');
         }
     }
     $Cache->generate_module_file($module_identifier, NO_FATAL_ERROR_CACHE);
     return MODULE_INSTALLED;
 }