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

📄 msgmgr.java~73~

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA~73~
📖 第 1 页 / 共 4 页
字号:
        String name;
        name = privilege.getUser(request);

        boolean re = false;
        MsgDb msgDb = new MsgDb();
        try {
            re = msgDb.AddReplyWE(application, request, name, fu);
        } catch (ErrMsgException e) {
            throw e;
        }

        if (re) {
            // 插件对应加入回贴的action
            String pluginCode = StrUtil.getNullString(fu.getFieldValue("pluginCode"));

            if (vplugin.size() > 0) {
                Iterator irplugin = vplugin.iterator();
                while (irplugin.hasNext()) {
                    PluginUnit pu = (PluginUnit) irplugin.next();
                    boolean isPlugin = false;
                    if (pu.getType().equals(pu.TYPE_BOARD))
                        isPlugin = true;
                    else if (pu.getType().equals(pu.TYPE_TOPIC) && pluginCode.equals(pu.getCode()))
                        isPlugin = true;
                    if (isPlugin) {
                        IPluginMsgAction ipa = pu.getMsgAction();
                        // logger.info("plugin name:" + pu.getName(request));
                        re = ipa.AddReply(application, request, msgDb, fu);
                    }
                }
            }
        }

        // 得分处理
        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.AddReply(application, request, msgDb);
            }
        }

        return true;
    }

    /**
     * 快速回复
     * @param application ServletContext
     * @param request HttpServletRequest
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean AddQuickReply(ServletContext application,
                                 HttpServletRequest request) throws
            ErrMsgException {
        long replyid = ParamUtil.getLong(request, "replyid");
        MsgDb md = getMsgDb(replyid);
        if (!privilege.canAddQuickReply(request, md.getboardcode(), md))
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID)); // "权限非法");

        String name = privilege.getUser(request); // 不能放在canAddQuickReply之前,这样可能会使得取得的name值为空,而在isUserLogin()中当session过期后,可以根据cookie重新登录,但之前如果取name值的话,就会为空

        MsgDb msgDb = new MsgDb();
        boolean re = msgDb.AddQuickReply(application, request, name);

        if (re) {
            String pluginCode = ParamUtil.get(request, "pluginCode");

            // 插件对应加入新贴的action
            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();
                    boolean isPlugin = false;
                    if (pu.getType().equals(pu.TYPE_BOARD))
                        isPlugin = true;
                    else if (pu.getType().equals(pu.TYPE_TOPIC) && pluginCode.equals(pu.getCode()))
                        isPlugin = true;
                    if (isPlugin) {
                        IPluginMsgAction ipa = pu.getMsgAction();
                        // logger.info("plugin name:" + pu.getName(request));
                        re = ipa.AddQuickReply(application, request,
                                               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));
            }

        // 插件对应删贴的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");
            s = StrUtil.format(s, new Object[] {msgDb.getTitle(), privilege.getUser(request)} );
            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");
                s = StrUtil.format(s, new Object[] {msg.getTitle(),
                                   privilege.getUser(request)});
                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);
    }

    /**
     * 更换标题颜色
     * @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");
        MsgDb msgDb = new MsgDb();

⌨️ 快捷键说明

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