Example #1
0
function xoops_module_uninstall($dirname)
{
    global $xoopsConfig;
    $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
    $db =& Database::getInstance();
    $module_handler =& xoops_gethandler('module');
    $module =& $module_handler->getByDirname($dirname);
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($module->getVar('mid'));
    if ($module->getVar('dirname') == 'system') {
        return "<p>" . sprintf(_MD_AM_FAILUNINS, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_SYSNO . "</p>";
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
        return "<p>" . sprintf(_MD_AM_FAILUNINS, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
    } else {
        $msgs = array();
        if (!$module_handler->delete($module)) {
            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete ' . $module->getVar('name') . '</span>';
        } else {
            // delete template files
            $tplfile_handler = xoops_gethandler('tplfile');
            $templates =& $tplfile_handler->find(null, 'module', $module->getVar('mid'));
            $tcount = count($templates);
            if ($tcount > 0) {
                $msgs[] = 'Deleting templates...';
                for ($i = 0; $i < $tcount; $i++) {
                    if (!$tplfile_handler->delete($templates[$i])) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete template ' . $templates[$i]->getVar('tpl_file') . ' from the database. Template ID: <b>' . $templates[$i]->getVar('tpl_id') . '</b></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Template <b>' . $templates[$i]->getVar('tpl_file') . '</b> deleted from the database. Template ID: <b>' . $templates[$i]->getVar('tpl_id') . '</b>';
                    }
                }
            }
            unset($templates);
            // delete blocks and block tempalte files
            $block_arr =& XoopsBlock::getByModule($module->getVar('mid'));
            if (is_array($block_arr)) {
                $bcount = count($block_arr);
                $msgs[] = 'Deleting block...';
                for ($i = 0; $i < $bcount; $i++) {
                    if (!$block_arr[$i]->delete()) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>' . $block_arr[$i]->getVar('name') . '</b> Block ID: <b>' . $block_arr[$i]->getVar('bid') . '</b></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Block <b>' . $block_arr[$i]->getVar('name') . '</b> deleted. Block ID: <b>' . $block_arr[$i]->getVar('bid') . '</b>';
                    }
                    if ($block_arr[$i]->getVar('template') != '') {
                        $templates =& $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
                        $btcount = count($templates);
                        if ($btcount > 0) {
                            for ($j = 0; $j < $btcount; $j++) {
                                if (!$tplfile_handler->delete($templates[$j])) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block template ' . $templates[$j]->getVar('tpl_file') . ' from the database. Template ID: <b>' . $templates[$j]->getVar('tpl_id') . '</b></span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Block template <b>' . $templates[$j]->getVar('tpl_file') . '</b> deleted from the database. Template ID: <b>' . $templates[$j]->getVar('tpl_id') . '</b>';
                                }
                            }
                        }
                        unset($templates);
                    }
                }
            }
            // delete tables used by this module
            $modtables = $module->getInfo('tables');
            if ($modtables != false && is_array($modtables)) {
                $msgs[] = 'Deleting module tables...';
                foreach ($modtables as $table) {
                    // prevent deletion of reserved core tables!
                    if (!in_array($table, $reservedTables)) {
                        $sql = 'DROP TABLE ' . $db->prefix($table);
                        if (!$db->query($sql)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not drop table <b>' . $db->prefix($table) . '<b>.</span>';
                        } else {
                            $msgs[] = '&nbsp;&nbsp;Table <b>' . $db->prefix($table) . '</b> dropped.</span>';
                        }
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Not allowed to drop table <b>' . $db->prefix($table) . '</b>!</span>';
                    }
                }
            }
            // delete comments if any
            if ($module->getVar('hascomments') != 0) {
                $msgs[] = 'Deleting comments...';
                $comment_handler =& xoops_gethandler('comment');
                if (!$comment_handler->deleteByModule($module->getVar('mid'))) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete comments</span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;Comments deleted';
                }
            }
            // RMV-NOTIFY
            // delete notifications if any
            if ($module->getVar('hasnotification') != 0) {
                $msgs[] = 'Deleting notifications...';
                if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete notifications</span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;Notifications deleted';
                }
            }
            // delete permissions if any
            $gperm_handler =& xoops_gethandler('groupperm');
            if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete group permissions</span>';
            } else {
                $msgs[] = '&nbsp;&nbsp;Group permissions deleted';
            }
            // delete module config options if any
            if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
                $config_handler =& xoops_gethandler('config');
                $configs =& $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
                $confcount = count($configs);
                if ($confcount > 0) {
                    $msgs[] = 'Deleting module config options...';
                    for ($i = 0; $i < $confcount; $i++) {
                        if (!$config_handler->deleteConfig($configs[$i])) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete config data from the database. Config ID: <b>' . $configs[$i]->getvar('conf_id') . '</b></span>';
                        } else {
                            $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>' . $configs[$i]->getVar('conf_id') . '</b>';
                        }
                    }
                }
            }
            // execute module specific install script if any
            $uninstall_script = $module->getInfo('onUninstall');
            if (false != $uninstall_script && trim($uninstall_script) != '') {
                include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
                if (function_exists('xoops_module_uninstall_' . $dirname)) {
                    $func = 'xoops_module_uninstall_' . $dirname;
                    if (!$func($module)) {
                        $msgs[] = 'Failed to execute <b>' . $func . '</b>';
                    } else {
                        $msgs[] = '<b>' . $func . '</b> executed successfully.';
                    }
                }
            }
            $msgs[] = '</code><p>' . sprintf(_MD_AM_OKUNINS, "<b>" . $module->getVar('name') . "</b>") . '</p>';
        }
        $ret = '<code>';
        foreach ($msgs as $msg) {
            $ret .= $msg . '<br />';
        }
        return $ret;
    }
}
Example #2
0
/**
 * @param $dirname
 *
 * @return string
 */
function xoops_module_uninstall($dirname)
{
    global $xoopsConfig;
    $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $module_handler = xoops_getHandler('module');
    $module = $module_handler->getByDirname($dirname);
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($module->getVar('mid'));
    if ($module->getVar('dirname') === 'system') {
        return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
        return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
    } else {
        $msgs = array();
        $msgs[] = '<div id="xo-module-log"><div class="header">';
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTALL . $module->getInfo('name', 's') . '</h4>';
        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
        }
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
        }
        $msgs[] = '</div><div class="logger">';
        // Load module specific install script if any
        $uninstall_script = $module->getInfo('onUninstall');
        if ($uninstall_script && trim($uninstall_script) != '') {
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
        }
        $func = "xoops_module_pre_uninstall_{$dirname}";
        // If pre uninstall function is defined, execute
        if (function_exists($func)) {
            $result = $func($module);
            if (false === $result) {
                $errs = $module->getErrors();
                $errs[] = sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func);
                return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
            } else {
                $prevErrs = $module->getErrors();
                array_unshift($prevErrs, '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>');
                $msgs = array_merge($msgs, $prevErrs);
            }
        }
        if (false === $module_handler->delete($module)) {
            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_DELETE_ERROR, $module->getVar('name')) . '</span>';
        } else {
            // delete template files
            $tplfile_handler = xoops_getHandler('tplfile');
            $templates = $tplfile_handler->find(null, 'module', $module->getVar('mid'));
            $tcount = count($templates);
            if ($tcount > 0) {
                $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_DELETE;
                for ($i = 0; $i < $tcount; ++$i) {
                    if (false === $tplfile_handler->delete($templates[$i])) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA_FAILD, $templates[$i]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$i]->getVar('tpl_id') . '</strong>') . '</span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA, '<strong>' . $templates[$i]->getVar('tpl_file') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$i]->getVar('tpl_id') . '</strong>');
                    }
                }
            }
            unset($templates);
            // delete blocks and block tempalte files
            $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
            if (is_array($block_arr)) {
                $bcount = count($block_arr);
                $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_DELETE;
                for ($i = 0; $i < $bcount; ++$i) {
                    if (false === $block_arr[$i]->delete()) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block_arr[$i]->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block_arr[$i]->getVar('bid') . '</strong>') . '</span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE, '<strong>' . $block_arr[$i]->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block_arr[$i]->getVar('bid') . '</strong>');
                    }
                    if ($block_arr[$i]->getVar('template') != '') {
                        $templates = $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
                        $btcount = count($templates);
                        if ($btcount > 0) {
                            for ($j = 0; $j < $btcount; ++$j) {
                                if (!$tplfile_handler->delete($templates[$j])) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_TEMPLATE_ERROR, $templates[$j]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$j]->getVar('tpl_id') . '</strong>') . '</span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_DATA, '<strong>' . $templates[$j]->getVar('tpl_file') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$j]->getVar('tpl_id') . '</strong>');
                                }
                            }
                        }
                        unset($templates);
                    }
                }
            }
            // delete tables used by this module
            $modtables = $module->getInfo('tables');
            if ($modtables != false && is_array($modtables)) {
                $msgs[] = _AM_SYSTEM_MODULES_DELETE_MOD_TABLES;
                foreach ($modtables as $table) {
                    // prevent deletion of reserved core tables!
                    if (!in_array($table, $reservedTables)) {
                        $sql = 'DROP TABLE ' . $db->prefix($table);
                        if (!$db->query($sql)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_ERROR, '<strong>' . $db->prefix($table) . '<strong>') . '</span>';
                        } else {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED, '<strong>' . $db->prefix($table) . '</strong>');
                        }
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_FAILDED, '<strong>' . $db->prefix($table) . '</strong>') . '</span>';
                    }
                }
            }
            // delete comments if any
            if ($module->getVar('hascomments') != 0) {
                $msgs[] = _AM_SYSTEM_MODULES_COMMENTS_DELETE;
                $comment_handler = xoops_getHandler('comment');
                if (false === $comment_handler->deleteByModule($module->getVar('mid'))) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_COMMENTS_DELETE_ERROR . '</span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_COMMENTS_DELETED;
                }
            }
            // RMV-NOTIFY
            // delete notifications if any
            if ($module->getVar('hasnotification') != 0) {
                $msgs[] = _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE;
                if (false === xoops_notification_deletebymodule($module->getVar('mid'))) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE_ERROR . '</span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETED;
                }
            }
            // delete permissions if any
            $gperm_handler = xoops_getHandler('groupperm');
            if (false === $gperm_handler->deleteByModule($module->getVar('mid'))) {
                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETE_ERROR . '</span>';
            } else {
                $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETED;
            }
            // delete module config options if any
            if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
                $config_handler = xoops_getHandler('config');
                $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
                $confcount = count($configs);
                if ($confcount > 0) {
                    $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
                    for ($i = 0; $i < $confcount; ++$i) {
                        if (false === $config_handler->deleteConfig($configs[$i])) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>';
                        } else {
                            $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>');
                        }
                    }
                }
            }
            // execute module specific install script if any
            $func = 'xoops_module_uninstall_' . $dirname;
            if (function_exists($func)) {
                if (!$func($module)) {
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
                } else {
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
                }
            }
            $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
        }
        $msgs[] = '</div></div>';
        $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
        $ret = implode('<br>', $msgs);
        return $ret;
    }
}
Example #3
0
function xoops_module_uninstall($dirname)
{
    global $xoopsConfig;
    $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
    $db =& Database::getInstance();
    $module_handler =& xoops_gethandler('module');
    $module = $module_handler->getByDirname($dirname);
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($module->getVar('mid'));
    if ($module->getVar('dirname') == 'system') {
        return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_SYSNO . "</p>";
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
        return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
    } else {
        $msgs = array();
        // Load module specific install script if any
        $uninstall_script = $module->getInfo('onUninstall');
        if ($uninstall_script && trim($uninstall_script) != '') {
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
        }
        $func = "xoops_module_pre_uninstall_{$dirname}";
        // If pre uninstall function is defined, execute
        if (function_exists($func)) {
            $result = $func($module);
            if (!$result) {
                $errs = $module->getErrors();
                $errs[] = sprintf(_MD_AM_FAILED_EXECUTE, $func);
                return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />" . implode("<br />", $errs) . "</p>";
            } else {
                $msgs = $module->getErrors();
                array_unshift($msgs, "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>");
            }
        }
        if (!$module_handler->delete($module)) {
            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_DELETE_ERROR, $module->getVar('name')) . '</span>';
        } else {
            // delete template files
            $tplfile_handler = xoops_gethandler('tplfile');
            $templates = $tplfile_handler->find(null, 'module', $module->getVar('mid'));
            $tcount = count($templates);
            if ($tcount > 0) {
                $msgs[] = _MD_AM_TEMPLATES_DELETE;
                for ($i = 0; $i < $tcount; $i++) {
                    if (!$tplfile_handler->delete($templates[$i])) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_DELETE_DATA_FAILD, $templates[$i]->getVar('tpl_file')) . sprintf(_MD_AM_TEMPLATE_ID, "<strong>" . $templates[$i]->getVar('tpl_id') . "</strong>") . '</span>';
                    } else {
                        $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TEMPLATE_DELETE_DATA, "<strong>" . $templates[$i]->getVar('tpl_file') . "</strong>") . sprintf(_MD_AM_TEMPLATE_ID, "<strong>" . $templates[$i]->getVar('tpl_id') . "</strong>");
                    }
                }
            }
            unset($templates);
            // delete blocks and block tempalte files
            $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
            if (is_array($block_arr)) {
                $bcount = count($block_arr);
                $msgs[] = _MD_AM_BLOCKS_DELETE;
                for ($i = 0; $i < $bcount; $i++) {
                    if (!$block_arr[$i]->delete()) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_BLOCK_DELETE_ERROR, "<strong>" . $block_arr[$i]->getVar('name') . "</strong>") . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $block_arr[$i]->getVar('bid') . "</strong>") . '</span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_MD_AM_BLOCK_DELETE, "<strong>" . $block_arr[$i]->getVar('name') . "</strong>") . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $block_arr[$i]->getVar('bid') . "</strong>");
                    }
                    if ($block_arr[$i]->getVar('template') != '') {
                        $templates = $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
                        $btcount = count($templates);
                        if ($btcount > 0) {
                            for ($j = 0; $j < $btcount; $j++) {
                                if (!$tplfile_handler->delete($templates[$j])) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_BLOCK_DELETE_TEMPLATE_ERROR, $templates[$j]->getVar('tpl_file')) . sprintf(_MD_AM_TEMPLATE_ID, "<strong>" . $templates[$j]->getVar('tpl_id') . "</strong>") . '</span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_MD_AM_BLOCK_DELETE_DATA, "<strong>" . $templates[$j]->getVar('tpl_file') . "</strong>") . sprintf(_MD_AM_TEMPLATE_ID, "<strong>" . $templates[$j]->getVar('tpl_id') . "</strong>");
                                }
                            }
                        }
                        unset($templates);
                    }
                }
            }
            // delete tables used by this module
            $modtables = $module->getInfo('tables');
            if ($modtables != false && is_array($modtables)) {
                $msgs[] = _MD_AM_DELETE_MOD_TABLES;
                foreach ($modtables as $table) {
                    // prevent deletion of reserved core tables!
                    if (!in_array($table, $reservedTables)) {
                        $sql = 'DROP TABLE ' . $db->prefix($table);
                        if (!$db->query($sql)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TABLE_DROPPED_ERROR, "<strong>" . $db->prefix($table) . "<strong>") . "</span>";
                        } else {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_MD_AM_TABLE_DROPPED, "<strong>" . $db->prefix($table) . "</strong>");
                        }
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TABLE_DROPPED_FAILDED, "<strong>" . $db->prefix($table) . "</strong>") . "</span>";
                    }
                }
            }
            // delete comments if any
            if ($module->getVar('hascomments') != 0) {
                $msgs[] = _MD_AM_COMMENTS_DELETE;
                $comment_handler =& xoops_gethandler('comment');
                if (!$comment_handler->deleteByModule($module->getVar('mid'))) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_COMMENTS_DELETE_ERROR . '</span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;' . _MD_AM_COMMENTS_DELETED;
                }
            }
            // RMV-NOTIFY
            // delete notifications if any
            if ($module->getVar('hasnotification') != 0) {
                $msgs[] = _MD_AM_NOTIFICATIONS_DELETE;
                if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_NOTIFICATIONS_DELETE_ERROR . '</span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;' . _MD_AM_NOTIFICATIONS_DELETED;
                }
            }
            // delete permissions if any
            $gperm_handler =& xoops_gethandler('groupperm');
            if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_GROUP_PERMS_DELETE_ERROR . '</span>';
            } else {
                $msgs[] = '&nbsp;&nbsp;' . _MD_AM_GROUP_PERMS_DELETED;
            }
            // delete module config options if any
            if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
                $config_handler =& xoops_gethandler('config');
                $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
                $confcount = count($configs);
                if ($confcount > 0) {
                    $msgs[] = _MD_AM_MODULE_DATA_DELETE;
                    for ($i = 0; $i < $confcount; $i++) {
                        if (!$config_handler->deleteConfig($configs[$i])) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_CONFIG_DATA_DELETE_ERROR . sprintf(_MD_AM_GONFIG_ID, "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>") . '</span>';
                        } else {
                            $msgs[] = '&nbsp;&nbsp;' . _MD_AM_GONFIG_DATA_DELETE . sprintf(_MD_AM_GONFIG_ID, "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>");
                        }
                    }
                }
            }
            // execute module specific install script if any
            $func = 'xoops_module_uninstall_' . $dirname;
            if (function_exists($func)) {
                if (!$func($module)) {
                    $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>";
                } else {
                    $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
                }
            }
            $msgs[] = '<p>' . sprintf(_MD_AM_OKUNINS, "<strong>" . $module->getVar('name') . "</strong>") . '</p>';
        }
        $ret = '<div>' . implode("<br />", $msgs) . '</div>';
        return $ret;
    }
}
Example #4
0
/**
 * Logic for uninstalling a module
 *
 * @todo	add installation_notify(), send status
 *
 * @param unknown_type $dirname
 * @return	string	Result messages for uninstallation
 */
function xoops_module_uninstall($dirname) {
	global $icmsConfig, $icmsAdminTpl;

	$reservedTables = array(
		'avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config',
		'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset',
		'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission',
		'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session',
		'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource',
		'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');

	$db =& icms_db_Factory::instance();
	$module_handler = icms::handler('icms_module');
	$module =& $module_handler->getByDirname($dirname);
	$module->registerClassPath();
	$icmsAdminTpl->template_clear_module_cache($module->getVar('mid'));
	if ($module->getVar('dirname') == 'system') {
		return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>")
		. "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_SYSNO . "</p>";
	} elseif ($module->getVar('dirname') == $icmsConfig['startpage']) {
		return "<p>" . sprintf(_MD_AM_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>")
		. "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
	} else {
		$msgs = array();

		$member_handler = icms::handler('icms_member');
		$grps = $member_handler->getGroupList();
		foreach ($grps as $k => $v) {
			$stararr = explode('-', $icmsConfig['startpage'][$k]);
			if (count($stararr) > 0) {
				if ($module->getVar('mid') == $stararr[0]) {
					return "<p>" . sprintf(_MD_AM_FAILDEACT, "<strong>" . $module->getVar('name')
					. "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO
					. "</p>";
				}
			}
		}
		if (in_array($module->getVar('dirname'), $icmsConfig ['startpage'])) {
			return "<p>" . sprintf(_MD_AM_FAILDEACT, "<strong>" . $module->getVar('name') . "</strong>")
			. "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
		}

		$page_handler = icms::handler('icms_data_page');
		$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('page_moduleid', $module->getVar('mid')));
		$pages = $page_handler->getCount($criteria);

		if ($pages > 0) {
			$pages = $page_handler->getObjects($criteria);
			$msgs[] = _MD_AM_SYMLINKS_DELETE;
			foreach ($pages as $page) {
				if (!$page_handler->delete($page)) {
					$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_SYMLINK_DELETE_FAIL . '</span>',
					$page->getVar('page_title'),  '<strong>'. $page->getVar('page_id') . '</strong>');
				} else {
					$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_SYMLINK_DELETED,
						'<strong>' . $page->getVar('page_title') . '</strong>', '<strong>' . $page->getVar('page_id') . '</strong>');
				}
			}
		}

		if (!$module_handler->delete($module)) {
			$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_DELETE_FAIL . '</span>', $module->getVar('name'));
		} else {
			// delete template files
			$tplfile_handler = icms::handler('icms_view_template_file');
			$templates =& $tplfile_handler->find(NULL, 'module', $module->getVar('mid'));
			$tcount = count($templates);
			if ($tcount > 0) {
				$msgs[] = _MD_AM_TEMPLATES_DELETE;
				for ($i = 0; $i < $tcount; $i++) {
					if (!$tplfile_handler->delete($templates[$i])) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_DELETE_FAIL . '</span>',
						$templates[$i]->getVar('tpl_file') , '<strong>' . icms_conv_nr2local($templates[$i]->getVar('tpl_id')) . '</strong>');
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_DELETED,
							'<strong>' . icms_conv_nr2local($templates[$i]->getVar('tpl_file')) . '</strong>',
							'<strong>' . icms_conv_nr2local($templates[$i]->getVar('tpl_id')) . '</strong>'
							);
					}
				}
			}
			unset($templates);

			// delete blocks and block template files
			$icms_block_handler = icms::handler('icms_view_block');
			$block_arr =& $icms_block_handler->getByModule($module->getVar('mid'));
			if (is_array($block_arr)) {
				$bcount = count($block_arr);
				$msgs[] = _MD_AM_BLOCKS_DELETE;
				for ($i = 0; $i < $bcount; $i++) {
					if (!$icms_block_handler->delete($block_arr[$i])) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_DELETE_FAIL . '</span>',
							'<strong>' . $block_arr[$i]->getVar('name') . '</strong>',
							'<strong>' . icms_conv_nr2local($block_arr[$i]->getVar('bid')) . '</strong>'
							);
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_DELETED,
							'<strong>' . $block_arr[$i]->getVar('name')	. '</strong>',
							'<strong>' . icms_conv_nr2local($block_arr[$i]->getVar('bid')) . '</strong>'
							);
					}
					if ($block_arr[$i]->getVar('template') != '') {
						$templates =& $tplfile_handler->find(NULL, 'block', $block_arr[$i]->getVar('bid'));
						$btcount = count($templates);
						if ($btcount > 0) {
							for ($j = 0; $j < $btcount; $j++) {
								if (!$tplfile_handler->delete($templates[$j])) {
									$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_TMPLT_DELETE_FAILED . '</span>',
									$templates[$j]->getVar('tpl_file'),
										'<strong>' . icms_conv_nr2local($templates[$j]->getVar('tpl_id')) . '</strong>'
										);
								} else {
									$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_TMPLT_DELETED,
										'<strong>' . $templates[$j]->getVar('tpl_file') . '</strong>',
										'<strong>' . icms_conv_nr2local($templates[$j]->getVar('tpl_id')) . '</strong>'
										);
								}
							}
						}
						unset($templates);
					}
				}
			}

			// delete tables used by this module
			$modtables = $module->getInfo('tables');
			if ($modtables !== FALSE && is_array($modtables)) {
				$msgs[] = _MD_AM_MOD_TABLES_DELETE;
				foreach ($modtables as $table) {
					// prevent deletion of reserved core tables!
					if (!in_array($table, $reservedTables)) {
						$sql = 'DROP TABLE ' . $db->prefix($table);
						if (!$db->query($sql)) {
							$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_MOD_TABLE_DELETE_FAIL . '</span>',
								'<strong>'. $db->prefix($table) . '<strong> . '
								);
						} else {
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_MOD_TABLE_DELETED,
								'<strong>' . $db->prefix($table) . '</strong>'
								);
						}
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_MOD_TABLE_DELETE_NOTALLOWED . '</span>',
							'<strong>' . $db->prefix($table) . '</strong>'
							);
					}
				}
			}

			// delete comments if any
			if ($module->getVar('hascomments') != 0) {
				$msgs[] = _MD_AM_COMMENTS_DELETE;
				$comment_handler = icms::handler('icms_data_comment');
				if (!$comment_handler->deleteByModule($module->getVar('mid'))) {
					$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_COMMENT_DELETE_FAIL . '</span>';
				} else {
					$msgs[] = '&nbsp;&nbsp;' . _MD_AM_COMMENT_DELETED;
				}
			}

			// delete notifications if any
			if ($module->getVar('hasnotification') != 0) {
				$msgs[] = _MD_AM_NOTIFICATIONS_DELETE;
				if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
					$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_NOTIFICATION_DELETE_FAIL .'</span>';
				} else {
					$msgs[] = '&nbsp;&nbsp;' . _MD_AM_NOTIFICATION_DELETED;
				}
			}

			// delete permissions if any
			$msgs[] = _MD_AM_GROUPPERM_DELETE;
			$gperm_handler = icms::handler('icms_member_groupperm');
			if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
				$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_GROUPPERM_DELETE_FAIL . '</span>';
			} else {
				$msgs[] = '&nbsp;&nbsp;' . _MD_AM_GROUPPERM_DELETED;
			}

			// delete module config options if any
			if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
				$config_handler = icms::handler('icms_config');
				$configs =& $config_handler->getConfigs(new icms_db_criteria_Item('conf_modid', $module->getVar('mid')));
				$confcount = count($configs);
				if ($confcount > 0) {
					$msgs[] = _MD_AM_CONFIGOPTIONS_DELETE;
					for ($i = 0; $i < $confcount; $i++) {
						if (!$config_handler->deleteConfig($configs[$i])) {
							$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_CONFIGOPTION_DELETE_FAIL .'</span>',
								'<strong>' . icms_conv_nr2local($configs[$i]->getvar('conf_id')) . '</strong>');
						} else {
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_CONFIGOPTION_DELETED,
								'<strong>' . icms_conv_nr2local($configs[$i]->getVar('conf_id')) . '</strong>');
						}
					}
				}
			}

			// delete autotasks
			$atasks = $module->getInfo('autotasks');
			if (isset($atasks) && is_array($atasks) && (count($atasks) > 0)) {
				$msgs[] = _MD_AM_AUTOTASKS_DELETE;
				$atasks_handler = &icms_getModuleHandler('autotasks', 'system');
				$criteria = new icms_db_criteria_Compo();
				$criteria->add(new icms_db_criteria_Item('sat_type', 'addon/' . $module->getInfo('dirname')));
				$atasks_handler->deleteAll($criteria);
				unset($atasks_handler, $criteria, $taskData);
			}
			unset($atasks);

			// delete urllinks
			$urllink_handler = icms::handler('icms_data_urllink');
			$urllink_handler->deleteAll(icms_buildCriteria(array("mid" => $module->getVar("mid"))));

			// delete files
			$file_handler = icms::handler('icms_data_file');
			$file_handler->deleteAll(icms_buildCriteria(array("mid" => $module->getVar("mid"))));

			// execute module specific install script if any
			$uninstall_script = $module->getInfo('onUninstall');
			$ModName = ($module->getInfo('modname') != '') ? trim($module->getInfo('modname')) : $dirname;
			if (FALSE !== $uninstall_script && trim($uninstall_script) != '') {
				include_once ICMS_MODULES_PATH . '/' . $dirname . '/' . trim($uninstall_script);
				if (function_exists('xoops_module_uninstall_' . $ModName)) {
					$func = 'xoops_module_uninstall_' . $ModName;
					if (!$func($module)) {
						$msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
					} else {
						$msgs[] = $module->messages;
						$msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
					}
				} elseif (function_exists('icms_module_uninstall_' . $ModName)) {
					$func = 'icms_module_uninstall_' . $ModName;
					if (!$func($module)) {
						$msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
					} else {
						$msgs[] = $module->messages;
						$msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
					}
				}
			}

			$msgs[] = '</code><p>' . sprintf(_MD_AM_OKUNINS, "<strong>" . $module->getVar('name') . "</strong>") . '</p>';
		}
		$ret = '<code>' . implode('<br />', $msgs);
		return $ret;
	}
}