📄 modulesadmin.php
字号:
return $ret;
}
}
else {
return "<p>".sprintf(_MD_AM_FAILINS, "<b>".$dirname."</b>")." "._MD_AM_ERRORSC."<br /> ".sprintf(_MD_AM_ALEXISTS, $dirname)."</p>";
}
}
function &xoops_module_gettemplate($dirname, $template, $block=false)
{
global $xoopsConfig;
$ret = '';
if ($block) {
$path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/blocks/'.$template;
} else {
$path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/'.$template;
}
if (!file_exists($path)) {
return $ret;
} else {
$lines = file($path);
}
if (!$lines) {
return $ret;
}
$count = count($lines);
for ($i = 0; $i < $count; $i++) {
$ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
}
return $ret;
}
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>")." "._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>")." "._MD_AM_ERRORSC."<br /> - "._MD_AM_STRTNO."</p>";
} else {
$msgs = array();
if (!$module_handler->delete($module)) {
$msgs[] = ' <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[] = ' <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[] = ' 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[] = ' <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[] = ' 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[] = ' <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[] = ' 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[] = ' <span style="color:#ff0000;">ERROR: Could not drop table <b>'.$db->prefix($table).'<b>.</span>';
} else {
$msgs[] = ' Table <b>'.$db->prefix($table).'</b> dropped.</span>';
}
} else {
$msgs[] = ' <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[] = ' <span style="color:#ff0000;">ERROR: Could not delete comments</span>';
} else {
$msgs[] = ' Comments deleted';
}
}
// RMV-NOTIFY
// delete notifications if any
if ($module->getVar('hasnotification') != 0) {
$msgs[] = 'Deleting notifications...';
if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
$msgs[] = ' <span style="color:#ff0000;">ERROR: Could not delete notifications</span>';
} else {
$msgs[] = ' Notifications deleted';
}
}
// delete permissions if any
$gperm_handler =& xoops_gethandler('groupperm');
if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
$msgs[] = ' <span style="color:#ff0000;">ERROR: Could not delete group permissions</span>';
} else {
$msgs[] = ' 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[] = ' <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[] = ' 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;
}
}
function xoops_module_activate($mid)
{
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->get($mid);
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_clear_module_cache($module->getVar('mid'));
$module->setVar('isactive', 1);
if (!$module_handler->insert($module)) {
$ret = "<p>".sprintf(_MD_AM_FAILACT, "<b>".$module->getVar('name')."</b>")." "._MD_AM_ERRORSC."<br />".$module->getHtmlErrors();
return $ret."</p>";
}
$blocks =& XoopsBlock::getByModule($module->getVar('mid'));
$bcount = count($blocks);
for ($i = 0; $i < $bcount; $i++) {
$blocks[$i]->setVar('isactive', 1);
$blocks[$i]->store();
}
return "<p>".sprintf(_MD_AM_OKACT, "<b>".$module->getVar('name')."</b>")."</p>";
}
function xoops_module_deactivate($mid)
{
global $xoopsConfig;
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->get($mid);
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_clear_module_cache($mid);
$module->setVar('isactive', 0);
if ($module->getVar('dirname') == "system") {
return "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")." "._MD_AM_ERRORSC."<br /> - "._MD_AM_SYSNO."</p>";
} elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
return "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")." "._MD_AM_ERRORSC."<br /> - "._MD_AM_STRTNO."</p>";
} else {
if (!$module_handler->insert($module)) {
$ret = "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")." "._MD_AM_ERRORSC."<br />".$module->getHtmlErrors();
return $ret."</p>";
}
$blocks =& XoopsBlock::getByModule($module->getVar('mid'));
$bcount = count($blocks);
for ($i = 0; $i < $bcount; $i++) {
$blocks[$i]->setVar('isactive', 0);
$blocks[$i]->store();
}
return "<p>".sprintf(_MD_AM_OKDEACT, "<b>".$module->getVar('name')."</b>")."</p>";
}
}
function xoops_module_change($mid, $weight, $name)
{
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->get($mid);
$module->setVar('weight', $weight);
$module->setVar('name', $name);
$myts =& MyTextSanitizer::getInstance();
if (!$module_handler->insert($module)) {
$ret = "<p>".sprintf(_MD_AM_FAILORDER, "<b>".$myts->stripSlashesGPC($name)."</b>")." "._MD_AM_ERRORSC."<br />";
$ret .= $module->getHtmlErrors()."</p>";
return $ret;
}
return "<p>".sprintf(_MD_AM_OKORDER, "<b>".$myts->stripSlashesGPC($name)."</b>")."</p>";
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -