⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgmgr.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                                               msgDb.getId());
                    }
                }
            }
        }

        // 得分处理
        if (re) {
            ScoreMgr sm = new ScoreMgr();
            Vector v = sm.getAllScore();
            Iterator ir = v.iterator();
            while (ir.hasNext()) {
                ScoreUnit su = (ScoreUnit) ir.next();
                IPluginScore ips = su.getScore();
                // 类是否存在
                if (ips!=null)
                    ips.AddQuickReply(application, request, msgDb.getId());
            }
        }
        return re;
    }

    /**
     * 删贴,如果版块定义默认删至回收站,则将其置入回收站
     * @param application ServletContext
     * @param request HttpServletRequest
     * @param delId long
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean delTopic(ServletContext application,
                            HttpServletRequest request, long delId) throws
            ErrMsgException {
        // Privilege privilege = new Privilege();
        // if (!privilege.isUserLogin(request))
        //    throw new ErrMsgException(SkinUtil.LoadString(request, "err_not_login"));

        boolean isPluginValid = false;

        MsgDb msgDb = getMsgDb(delId);
        if (!msgDb.isLoaded())
            throw new ErrMsgException(LoadString(request, "err_topic_del_lost"));

        blog = msgDb.isBlog();

        PluginMgr pm = new PluginMgr();
        Vector vplugin = pm.getAllPluginUnitOfBoard(msgDb.getboardcode());
        if (vplugin.size() > 0) {
            Iterator irplugin = vplugin.iterator();
            while (irplugin.hasNext()) {
                PluginUnit pu = (PluginUnit) irplugin.next();
                IPluginPrivilege ipp = pu.getPrivilege();
                // logger.info("plugin name:" + pu.getName(request));
                if (!ipp.canManage(request, delId)) {
                    String s = LoadString(request, "err_pvg_plugin");
                    s = s.replaceFirst("\\$p", pu.getName(request));
                    throw new ErrMsgException(s);
                }
            }
            isPluginValid = true;
        }

        // 如果在插件的权限设置中允许管理,则不再检查用户是否为版主,反之则检查
        if (!isPluginValid) {
            if (!privilege.canManage(request, delId)) {
                throw new ErrMsgException(SkinUtil.LoadString(request,
                        SkinUtil.PVG_INVALID));
            }
        }

        Leaf lf = new Leaf();
        lf = lf.getLeaf(msgDb.getboardcode());
        // 如果版块设置删除时放至回收站
        if (lf.getDelMode()==lf.DEL_DUSTBIN) {
            try {
                return msgDb.checkMsg(msgDb.CHECK_STATUS_DUSTBIN);
            }
            catch (ResKeyException e) {
                throw new ErrMsgException(e.getMessage(request));
            }
        }

        // 插件对应删贴的action
        if (vplugin.size() > 0) {
            Iterator irplugin = vplugin.iterator();
            while (irplugin.hasNext()) {
                PluginUnit pu = (PluginUnit) irplugin.next();
                IPluginMsgAction ipa = pu.getMsgAction();
                // logger.info("plugin name:" + pu.getName(request));
                ipa.delTopic(application, request, msgDb);
            }
        }

        // 删除贴子的plugin2插件
        String plugin2Code = msgDb.getPlugin2Code();
        if (!plugin2Code.equals("")) {
            Plugin2Mgr p2m = new Plugin2Mgr();
            Plugin2Unit p2u = p2m.getPlugin2Unit(plugin2Code);
            if (p2u != null) {
                p2u.getMsgAction().delTopic(application, request, msgDb);
            }
        }

        boolean re = false;
        try {
            re = msgDb.delTopic(application, delId);

            // 发送短消息提醒用户主题被删除
            MessageDb msg = new MessageDb();
            msg.setTitle(SkinUtil.LoadString(request, "res.forum.MsgDb",
                                             "shortmsg_del_topic_title"));
            String s = SkinUtil.LoadString(request, "res.forum.MsgDb",
                                           "shortmsg_del_topic_content");
            if (!privilege.isUserLogin(request)) {
                s = StrUtil.format(s, new Object[] {msgDb.getTitle(),
                                   "Administrators"}); // @task
            } else {
                UserDb ud = new UserDb();
                ud = ud.getUser(privilege.getUser(request));
                s = StrUtil.format(s, new Object[] {msgDb.getTitle(),
                                   ud.getNick()});
            }
            msg.setContent(s);
            msg.setSender(msg.USER_SYSTEM);
            msg.setReceiver(msgDb.getName());
            msg.setIp(request.getRemoteAddr());
            msg.setType(msg.TYPE_SYSTEM);
            msg.create();
        } catch (ResKeyException e1) {
            logger.error("delTopic:" + e1.getMessage(request));
        }

        return re;
    }

    /**
     * 彻底删除贴子,用于回收站中的操作
     * @param application ServletContext
     * @param request HttpServletRequest
     * @param delId long
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean delTopicAbsolutely(ServletContext application,
                            HttpServletRequest request, long delId) throws
            ErrMsgException {
        // Privilege privilege = new Privilege();
        // if (!privilege.isUserLogin(request))
        //    throw new ErrMsgException(SkinUtil.LoadString(request, "err_not_login"));

        boolean isPluginValid = false;

        MsgDb msgDb = getMsgDb(delId);
        if (!msgDb.isLoaded())
            throw new ErrMsgException(LoadString(request, "err_topic_del_lost"));

        blog = msgDb.isBlog();

        PluginMgr pm = new PluginMgr();
        Vector vplugin = pm.getAllPluginUnitOfBoard(msgDb.getboardcode());
        if (vplugin.size() > 0) {
            Iterator irplugin = vplugin.iterator();
            while (irplugin.hasNext()) {
                PluginUnit pu = (PluginUnit) irplugin.next();
                IPluginPrivilege ipp = pu.getPrivilege();
                // logger.info("plugin name:" + pu.getName(request));
                if (!ipp.canManage(request, delId)) {
                    String s = LoadString(request, "err_pvg_plugin");
                    s = s.replaceFirst("\\$p", pu.getName(request));
                    throw new ErrMsgException(s);
                }
            }
            isPluginValid = true;
        }

        // 如果在插件的权限设置中允许管理,则不再检查用户是否为版主,反之则检查
        if (!isPluginValid) {
            if (!privilege.canManage(request, delId)) {
                throw new ErrMsgException(SkinUtil.LoadString(request,
                        SkinUtil.PVG_INVALID));
            }
        }

        // 插件对应删贴的action
        if (vplugin.size() > 0) {
            Iterator irplugin = vplugin.iterator();
            while (irplugin.hasNext()) {
                PluginUnit pu = (PluginUnit) irplugin.next();
                IPluginMsgAction ipa = pu.getMsgAction();
                // logger.info("plugin name:" + pu.getName(request));
                ipa.delTopic(application, request, msgDb);
            }
        }

        // 删除贴子的plugin2插件
        String plugin2Code = msgDb.getPlugin2Code();
        if (!plugin2Code.equals("")) {
            Plugin2Mgr p2m = new Plugin2Mgr();
            Plugin2Unit p2u = p2m.getPlugin2Unit(plugin2Code);
            if (p2u != null) {
                p2u.getMsgAction().delTopic(application, request, msgDb);
            }
        }

        boolean re = false;
        try {
            re = msgDb.delTopic(application, delId);

            // 发送短消息提醒用户主题被删除
            MessageDb msg = new MessageDb();
            msg.setTitle(SkinUtil.LoadString(request, "res.forum.MsgDb", "shortmsg_del_topic_title"));
            String s = SkinUtil.LoadString(request, "res.forum.MsgDb", "shortmsg_del_topic_content");
            if (!privilege.isUserLogin(request)) {
                s = StrUtil.format(s, new Object[] {msgDb.getTitle(),
                                   "Administrators"}); // @task
            }
            else {
                UserDb ud = new UserDb();
                ud = ud.getUser(privilege.getUser(request));
                s = StrUtil.format(s, new Object[] {msgDb.getTitle(),
                                   ud.getNick()});
            }
            msg.setContent(s);
            msg.setSender(msg.USER_SYSTEM);
            msg.setReceiver(msgDb.getName());
            msg.setIp(request.getRemoteAddr());
            msg.setType(msg.TYPE_SYSTEM);
            msg.create();
        } catch (ResKeyException e1) {
            logger.error("delTopic:" + e1.getMessage(request));
        }

        return re;
    }
    /**
     * 置顶
     * @param request HttpServletRequest
     * @param id long
     * @param value int
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean setOnTop(HttpServletRequest request, long id, int value) throws
            ErrMsgException {
        if (!privilege.canManage(request, id)) {
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
        }

        boolean re = false;

        MsgDb msg = getMsgDb(id);
        int oldlevel = msg.getLevel();
        try {
            re = msg.setOnTop(value);
        }
        catch (ResKeyException e) {
            throw new ErrMsgException(e.getMessage(request));
        }
        if (re) {
            if (msg.getLevel()==MsgDb.LEVEL_TOP_BOARD || msg.getLevel()==MsgDb.LEVEL_TOP_FORUM) {
                // 发送短消息提醒用户主题被置顶
                MessageDb shortmsg = new MessageDb();
                shortmsg.setTitle(SkinUtil.LoadString(request, "res.forum.MsgDb",
                                                 "shortmsg_set_ontop_title"));
                String s = SkinUtil.LoadString(request, "res.forum.MsgDb",
                                               "shortmsg_set_ontop_content");
                UserDb ud = new UserDb();
                ud = ud.getUser(privilege.getUser(request));
                s = StrUtil.format(s, new Object[] {msg.getTitle(),
                                   ud.getNick()});
                shortmsg.setContent(s);
                shortmsg.setSender(shortmsg.USER_SYSTEM);
                shortmsg.setReceiver(msg.getName());
                shortmsg.setIp(request.getRemoteAddr());
                shortmsg.setType(shortmsg.TYPE_SYSTEM);
                shortmsg.create();
            }
        }
        if (re && oldlevel == MsgDb.LEVEL_TOP_FORUM ||
            value == MsgDb.LEVEL_TOP_FORUM) {
            ForumCache rc = new ForumCache(new ForumDb());
            rc.refreshTopMsgs();
        }
        return re;
    }

    /**
     * 锁定贴子
     * @param request HttpServletRequest
     * @param id long
     * @param value int
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean setLocked(HttpServletRequest request, long id,
                             int value) throws ErrMsgException {
        if (!privilege.canManage(request, id)) {
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
        }

        MsgDb msgDb = new MsgDb();
        boolean re = false;
        try {
            re = msgDb.setLocked(id, value);
        }
        catch (ResKeyException e) {
            throw new ErrMsgException(e.getMessage(request));
        }
        return re;
    }

    /**
     * 更改贴子的版块
     * @param request HttpServletRequest
     * @param id long
     * @param newboardcode String
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean ChangeBoard(HttpServletRequest request, long id,
                               String newboardcode) throws ErrMsgException {
        if (!privilege.canManage(request, id)) {
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
        }
        MsgDb msgDb = new MsgDb();
        String name = privilege.getUser(request);
        return msgDb.ChangeBoard(request, id, newboardcode, name);
    }

    public boolean checkMsg(HttpServletRequest request, long id, int checkStatus) throws ErrMsgException {
        if (!privilege.canManage(request, id)) {
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
        }
        boolean re = false;
        MsgDb msgDb = getMsgDb(id);
        try {
            re = msgDb.checkMsg(checkStatus);
        }
        catch (ResKeyException e) {
            throw new ErrMsgException(e.getMessage(request));
        }
        return re;
    }

    /**
     * 更换标题颜色
     * @param request HttpServletRequest
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean ChangeColor(HttpServletRequest request) throws
            ErrMsgException {
        long id = ParamUtil.getLong(request, "id");
        if (!privilege.canManage(request, id)) {
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
        }

        String colorExpire = ParamUtil.get(request, "colorExpire");
        Date edate = null;
        try {
            edate = DateUtil.parse(colorExpire, "yyyy-MM-dd");
        }
        catch (Exception e) {
            logger.error("ChangeColor:" + e.getMessage());
        }
        if (edate==null)
            throw new ErrMsgException(LoadString(request, "err_expire_date"));

        String color = ParamUtil.get(request, "color");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -