예제 #1
0
 public static function update_module($module_id, $activated)
 {
     $error = '';
     if (!$activated) {
         MenuService::delete_mini_module($module_id);
         MenuService::delete_module_feeds_menus($module_id);
         $general_config = GeneralConfig::load();
         $module_home_page_selected = $general_config->get_module_home_page();
         if ($module_home_page_selected == $module_id) {
             $general_config->set_module_home_page('');
             $general_config->set_other_home_page('index.php');
         }
         $editors = AppContext::get_content_formatting_service()->get_available_editors();
         if (in_array($module_id, $editors)) {
             if (count($editors) > 1) {
                 $default_editor = ContentFormattingConfig::load()->get_default_editor();
                 if ($default_editor !== $module_id) {
                     PersistenceContext::get_querier()->update(DB_TABLE_MEMBER, array('editor' => $default_editor), 'WHERE editor=:old_editor', array('old_editor' => 'bbcode'));
                 } else {
                     $error = LangLoader::get_message('is_default_editor', 'editor-common');
                 }
             } else {
                 $error = LangLoader::get_message('last_editor_installed', 'editor-common');
             }
         }
     } else {
         $module = self::get_module($module_id);
         if ($module->get_configuration()->get_compatibility() != GeneralConfig::load()->get_phpboost_major_version()) {
             $error = LangLoader::get_message('modules.not_compatible', 'admin-modules-common');
         }
     }
     if (empty($error)) {
         $module = self::get_module($module_id);
         $module->set_activated($activated);
         ModulesConfig::load()->update($module);
         ModulesConfig::save();
         MenuService::generate_cache();
         Feed::clear_cache($module_id);
         if (ServerEnvironmentConfig::load()->is_url_rewriting_enabled()) {
             HtaccessFileCache::regenerate();
         }
     }
     return $error;
 }
 function uninstall_module($module_id, $drop_files)
 {
     global $Cache, $Sql, $CONFIG, $MODULES;
     $module_name = $Sql->query("SELECT name FROM " . DB_TABLE_MODULES . " WHERE id = '" . $module_id . "'", __LINE__, __FILE__);
     if (!empty($module_id) && !empty($module_name)) {
         $Sql->query_inject("DELETE FROM " . DB_TABLE_MODULES . " WHERE id = '" . $module_id . "'", __LINE__, __FILE__);
         $info_module = load_ini_file(PATH_TO_ROOT . '/' . $module_name . '/lang/', get_ulang());
         $Cache->delete_file($module_name);
         if (!empty($info_module['com'])) {
             $Sql->query_inject("DELETE FROM " . DB_TABLE_COM . " WHERE script = '" . addslashes($info_module['com']) . "'", __LINE__, __FILE__);
         }
         if (!empty($info_module)) {
             $Sql->query_inject("DELETE FROM " . DB_TABLE_CONFIGS . " WHERE name = '" . addslashes($module_name) . "'", __LINE__, __FILE__);
         }
         import('core/menu_service');
         MenuService::delete_mini_module($module_name);
         MenuService::delete_module_feeds_menus($module_name);
         $dir_db_module = get_ulang();
         $dir = PATH_TO_ROOT . '/' . $module_name . '/db';
         import('io/filesystem/folder');
         $folder_path = new Folder($dir . '/' . $dir_db_module);
         foreach ($folder_path->get_folders('`^[a-z0-9_ -]+$`i') as $dir) {
             $dir_db_module = $dir->get_name();
             break;
         }
         if (file_exists(PATH_TO_ROOT . '/' . $module_name . '/db/' . $dir_db_module . '/uninstall_' . $module_name . '.' . DBTYPE . '.sql')) {
             $Sql->parse(PATH_TO_ROOT . '/' . $module_name . '/db/' . $dir_db_module . '/uninstall_' . $module_name . '.' . DBTYPE . '.sql', PREFIX);
         }
         if (file_exists(PATH_TO_ROOT . '/' . $module_name . '/db/' . $dir_db_module . '/uninstall_' . $module_name . '.php')) {
             @(include_once PATH_TO_ROOT . '/' . $module_name . '/db/' . $dir_db_module . '/uninstall_' . $module_name . '.php');
         }
         $Cache->Generate_file('modules');
         $Cache->Generate_file('css');
         MenuService::generate_cache();
         import('content/syndication/feed');
         Feed::clear_cache();
         if ($CONFIG['rewrite'] == 1 && !empty($info_module['url_rewrite'])) {
             $Cache->Generate_file('htaccess');
         }
         if ($drop_files) {
             $folder = new Folder(PATH_TO_ROOT . '/' . $module_name);
             if (!$folder->delete()) {
                 return MODULE_FILES_COULD_NOT_BE_DROPPED;
             }
         }
         return MODULE_UNINSTALLED;
     } else {
         return NOT_INSTALLED_MODULE;
     }
 }