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

📄 msgmgr.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        MsgDb msgDb = new MsgDb();
        boolean re = false;
        try {
            re = msgDb.ChangeColor(id, color, edate);
        }
        catch (ResKeyException e) {
            throw new ErrMsgException(e.getMessage(request));
        }
        return re;
    }

    /**
     * 标题加粗
     * @param request HttpServletRequest
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean ChangeBold(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 boldExpire = ParamUtil.get(request, "boldExpire");
        Date edate = null;
        try {
            edate = DateUtil.parse(boldExpire, "yyyy-MM-dd");
        }
        catch (Exception e) {
            logger.error("ChangeBold:" + e.getMessage());
        }
        if (edate==null)
            throw new ErrMsgException(LoadString(request, "err_expire_date"));

        String sBold = ParamUtil.get(request, "isBold");
        int intBold = 0;
        if (!sBold.equals("")) {
            if (StrUtil.isNumeric(sBold))
                intBold = Integer.parseInt(sBold);
        }
        MsgDb msgDb = new MsgDb();
        boolean re = false;
        try {
            re = msgDb.ChangeBold(id, intBold, edate);
        }
        catch (ResKeyException e) {
            throw new ErrMsgException(e.getMessage(request));
        }
        return re;
    }

    /**
     * 置为精华
     * @param request HttpServletRequest
     * @param id long
     * @param value int
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean setElite(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();
        msgDb = msgDb.getMsgDb(id);
        boolean re = false;
        try {
            re = msgDb.setElite(value);

            // 发送短消息提醒用户主题被置为精华
            if (value==1) {
                MessageDb shortmsg = new MessageDb();
                shortmsg.setTitle(SkinUtil.LoadString(request, "res.forum.MsgDb",
                                                      "shortmsg_set_elite_title"));
                String s = SkinUtil.LoadString(request, "res.forum.MsgDb",
                                               "shortmsg_set_elite_content");
                UserDb ud = new UserDb();
                ud = ud.getUser(privilege.getUser(request));
                s = StrUtil.format(s, new Object[] {msgDb.getTitle(),
                                   ud.getNick()});
                shortmsg.setContent(s);
                shortmsg.setSender(shortmsg.USER_SYSTEM);
                shortmsg.setReceiver(msgDb.getName());
                shortmsg.setIp(request.getRemoteAddr());
                shortmsg.setType(shortmsg.TYPE_SYSTEM);
                shortmsg.create();
            }
        }
        catch (ResKeyException e) {
            throw new ErrMsgException(e.getMessage(request));
        }
        return re;
    }

    /**
     * 编辑高级方式发布的贴子
     * @param application ServletContext
     * @param request HttpServletRequest
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean editTopicWE(ServletContext application,
                               HttpServletRequest request) throws
            ErrMsgException {
        MultiFileUpload mfu = (MultiFileUpload)doUpload(application, request);

        String name, boardcode;
        boardcode = mfu.getFieldValue("boardcode");
        if (boardcode == null || boardcode.trim().equals(""))
            throw new ErrMsgException(LoadString(request, "err_need_board"));

        Privilege privilege = new Privilege();

        MsgDb md = new MsgDb();
        long editid = Long.parseLong(mfu.getFieldValue("editid"));
        md = md.getMsgDb(editid);
        if (md==null || !md.isLoaded())
            throw new ErrMsgException(SkinUtil.LoadString(request, "err_msg_lost"));

        if (!privilege.canEdit(request, md))
            return false;

        name = privilege.getUser(request);

        boolean re = md.editTopicWE(application, request, name, mfu);
        if (re)
            blog = md.isBlog();
        if (re) {
            // 编辑plugin2插件
            String plugin2Code = md.getPlugin2Code();
            if (!plugin2Code.equals("")) {
                Plugin2Mgr p2m = new Plugin2Mgr();
                Plugin2Unit p2u = p2m.getPlugin2Unit(plugin2Code);
                if (p2u != null) {
                    p2u.getMsgAction().editTopic(application, request, md,
                                                 mfu);
                }
            }
        }
        if (re) {
            // 插件对应编辑贴子的action
            String pluginCode = md.getRootMsgPluginCode();
            logger.info("edittopicwe:pluginCode=" + pluginCode);
            PluginMgr pm = new PluginMgr();
            Vector vplugin = pm.getAllPluginUnitOfBoard(boardcode);
            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;
                    logger.info("edittopicwe: pu.getCode()=" + pu.getCode() + " pluginCode=" + pluginCode);
                    if (isPlugin) {
                        IPluginMsgAction ipa = pu.getMsgAction();
                        re = ipa.editTopic(application, request, md, mfu);
                    }
                }
            }
        }
        return re;
    }

    /**
     * 编辑普通及UBB方式发的贴子
     * @param application ServletContext
     * @param request HttpServletRequest
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean editTopic(ServletContext application,
                             HttpServletRequest request) throws ErrMsgException {
        Privilege privilege = new Privilege();
        if (!privilege.isUserLogin(request))
            throw new ErrMsgException(SkinUtil.LoadString(request, "err_not_login")); // "请先登录!");

        FileUpload fu = doUpload(application, request);
        String boardcode = fu.getFieldValue("boardcode");
        if (boardcode == null || boardcode.trim().equals(""))
            throw new ErrMsgException(LoadString(request, "err_need_board"));

        MsgDb md = new MsgDb();
        long editid = Long.parseLong(fu.getFieldValue("editid"));
        md = getMsgDb(editid);

        if (!privilege.canEdit(request, md))
            return false;

        String name = privilege.getUser(request);

        boolean re = md.editTopic(application, request, name, fu);
        if (re)
            blog = md.isBlog();

        if (re) {
            String plugin2Code = md.getPlugin2Code();
            if (!plugin2Code.equals("")) {
                Plugin2Mgr p2m = new Plugin2Mgr();
                Plugin2Unit p2u = p2m.getPlugin2Unit(plugin2Code);
                if (p2u != null) {
                    p2u.getMsgAction().editTopic(application, request, md,
                                                 fu);
                }
            }
        }

        if (re) {
            // 插件对应编辑贴子的action
            String pluginCode = md.getRootMsgPluginCode();

            PluginMgr pm = new PluginMgr();
            Vector vplugin = pm.getAllPluginUnitOfBoard(boardcode);
            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.editTopic(application, request, md, fu);
                    }
                }
            }
        }
        return re;
    }

    /**
     * 投票
     * @param request HttpServletRequest
     * @return boolean
     * @throws ErrMsgException
     */
    public boolean vote(HttpServletRequest request) throws ErrMsgException {
        long voteid = ParamUtil.getLong(request, "voteid");
        Privilege privilege = new Privilege();
        if (!privilege.isUserLogin(request))
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.ERR_NOT_LOGIN));
        String[] opts = ParamUtil.getParameters(request, "votesel");
        if (opts==null)
            throw new ErrMsgException(MsgDb.LoadString(request, "err_vote_none"));

        String name = privilege.getUser(request);

        MsgDb msgDb = getMsgDb(voteid);
        if (msgDb.getIsLocked()==1)
            throw new ErrMsgException(msgDb.LoadString(request, "err_locked")); // "该贴已被锁定!");

        if (!privilege.canUserDo(request, msgDb.getboardcode(), "vote"))
            throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));

        MsgPollDb mpd = new MsgPollDb();
        mpd = (MsgPollDb)mpd.getQObjectDb(new Long(msgDb.getId()));

        Date d = mpd.getDate("expire_date");

        // 检查是否已过期
        if (d!=null) {
            if (DateUtil.compare(d, new java.util.Date()) != 1)
                throw new ErrMsgException(StrUtil.format(msgDb.LoadString(request,
                        "err_vote_expire"),
                                          new Object[] {ForumSkin.formatDate(request, d)}));
        }


        int len = opts.length;
        int max_choice = mpd.getInt("max_choice");
        if (len > max_choice) {
            throw new ErrMsgException(StrUtil.format(msgDb.LoadString(request,
                    "err_vote_max_count"),
                                          new Object[] {"" + max_choice}));
        }

        // 检查用户是否已投过票
        MsgPollOptionDb mpod = new MsgPollOptionDb();
        Vector v = mpd.getOptions(voteid);
        int optLen = v.size();
        for (int i=0; i<optLen; i++) {
            MsgPollOptionDb mo = mpod.getMsgPollOptionDb(voteid, i);
            String vote_user = StrUtil.getNullString(mo.getString("vote_user"));
            String[] ary = StrUtil.split(vote_user, ",");
            // System.out.println(getClass() + " ary=" + ary);
            if (ary!=null) {
                int len2 = ary.length;
                for (int k=0; k<len2; k++) {
                    if (ary[k].equals(name))
                        throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.MsgDb", "err_vote_repeat"));
                }
            }
        }

        boolean re = true;
        for (int i=0; i<len; i++) {
            MsgPollOptionDb mo = mpod.getMsgPollOptionDb(voteid, StrUtil.toInt(opts[i]));
            mo.set("vote_count", new Integer(mo.getInt("vote_count") + 1));
            String vote_user = StrUtil.getNullString(mo.getString("vote_user"));
            if (vote_user.equals(""))
                vote_user = name;
            else
                vote_user += "," + name;
            mo.set("vote_user", vote_user);
            try {
                re = mo.save();
            }
            catch (ResKeyException e) {
                throw new ErrMsgException(e.getMessage(request));
            }
        }

        return re;
    }

    public Vector getBoardManagers(String boardcode) {
        MsgDb msgDb = new MsgDb();
        return msgDb.getBoardManagers(boardcode);
    }

    public String getprivurl() {
        String privurl = "";
        if (privurl!=null)
            privurl = fileUpload.getFieldValue("privurl");
        return privurl;
    }

    public String getCurBoardCode() {
        String boardcode = StrUtil.getNullString(fileUpload.getFieldValue("boardcode"));
        return boardcode;
    }

    public void setId(long id) {
        this.id = id;
    }

    public void setBlog(boolean blog) {
        this.blog = blog;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getId() {
        return id;
    }

    public boolean isBlog() {
        return blog;
    }

    public String getName() {
        return name;
    }

    private long id = -1;
    private boolean blog;
    private String name;

}

⌨️ 快捷键说明

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