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

📄 msgdb.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                } else {
                    // 将附件保存至磁盘
                    writeAttachmentResult = mfu.writeAttachment(true); // 用随机名称命名文件
                    // 保存成功(磁盘空间允许)
                    if (writeAttachmentResult==mfu.WRITE_ATTACHMENT_SUCCEED) {
                        Vector attachs = mfu.getAttachments();
                        Iterator ir = attachs.iterator();
                        // 将附件保存至数据库
                        while (ir.hasNext()) {
                            FileInfo fi = (FileInfo) ir.next();
                            String fpath = mfu.getSavePath() + fi.getDiskName();
                            long attachId = SequenceMgr.nextID(SequenceMgr.SQ_MESSAGE_ATTACH);

                            sql =
                                    "insert into sq_message_attach (id,fullpath,msgId,name,diskname,visualpath,orders,UPLOAD_DATE,FILE_SIZE,USER_NAME) values (" +
                                    attachId + "," +
                                    StrUtil.sqlstr(fpath) + "," + id + "," +
                                    StrUtil.sqlstr(fi.getName()) + "," +
                                    StrUtil.sqlstr(fi.getDiskName()) + "," +
                                    StrUtil.sqlstr(FilePath) + "," + orders +
                                    "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + fi.getSize() + "," + StrUtil.sqlstr(name) + ")";
                            conn.executeUpdate(sql);
                            orders++;
                        }
                        if (attachs.size()>0) {
                            // 加分
                            ScoreMgr sm = new ScoreMgr();
                            Vector vatt = sm.getAllScore();
                            Iterator iratt = vatt.iterator();
                            while (iratt.hasNext()) {
                                ScoreUnit su = (ScoreUnit) iratt.next();
                                IPluginScore ips = su.getScore();
                                if (ips != null)
                                    ips.onAddAttachment(name, attachs.size());
                            }
                        }
                        UserPrivDb upd = new UserPrivDb();
                        upd = upd.getUserPrivDb(name);
                        upd.addAttachTodayUploadCount(orders- 1);

                    }
                }
            } catch (Exception e1) {
                Logger.getLogger(MsgDb.class.getName()).info("AddNewWE:" + e1.getMessage());
            } finally {
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            }
        } else {
            throw new ErrMsgException(mfu.getErrMessage(request));
        }
        if (writeAttachmentResult==mfu.DISKSPACEUSED_TOO_LARGE)
            throw new ErrMsgException(LoadString(request, "err_space_full")); // "虚拟磁盘空间已满,附件未能写入!");
        return true;
    }

    public boolean CheckReply(HttpServletRequest req, FileUpload fu) throws ErrMsgException {
        String strreplyid = fu.getFieldValue("replyid");
        if (strreplyid == null)
            throw new ErrMsgException(LoadString(req, "err_need_reply_id")); // "缺少回贴标识!");
        if (!strreplyid.equals(""))
            replyid = Integer.parseInt(strreplyid);
        CheckTopic(req, fu);

        // 检查发贴是否需审核
        TimeConfig tc = new TimeConfig();
        if (tc.isPostNeedCheck(req)) {
            checkStatus = CHECK_STATUS_NOT;
        }
        else {
            Leaf lf = new Leaf();
            lf = lf.getLeaf(boardcode);
            // 回贴是否需审核
            if (lf.getCheckMsg() == Leaf.CHECK_TOPIC_REPLY) {
                checkStatus = CHECK_STATUS_NOT;
            } else
                checkStatus = CHECK_STATUS_PASS;
        }
        return true;
    }

    public boolean CheckReplyWE(HttpServletRequest req, FileUpload fu) throws ErrMsgException {
        String strreplyid = fu.getFieldValue("replyid");
        if (strreplyid == null)
            throw new ErrMsgException(LoadString(req, "err_need_reply_id")); // "缺少回贴标识!");
        if (!strreplyid.equals(""))
            replyid = Integer.parseInt(strreplyid);
        CheckTopicWE(req, fu);
        isWebedit = WEBEDIT_REDMOON;

        // 检查发贴是否需审核
        TimeConfig tc = new TimeConfig();
        if (tc.isPostNeedCheck(req)) {
            checkStatus = CHECK_STATUS_NOT;
        }
        else {
            Leaf lf = new Leaf();
            lf = lf.getLeaf(boardcode);
            if (lf.getCheckMsg() == Leaf.CHECK_TOPIC_REPLY) {
                checkStatus = CHECK_STATUS_NOT;
            } else
                checkStatus = CHECK_STATUS_PASS;
        }
        return true;
    }

    /**
     * 发回复贴(普通和UBB方式)
     * @param application ServletContext
     * @param request HttpServletRequest
     * @param name String
     * @param fu FileUpload
     * @return boolean
     * @throws ErrMsgException
     */
    public synchronized boolean AddReply(ServletContext application,
                            HttpServletRequest request, String name, FileUpload fu) throws
            ErrMsgException {
        this.name = name;
        // 回复合法性检查
        CheckReply(request, fu);
        int length = 0;
        if (title != null)
            length = title.length();

        if (length < MIN_TOPIC_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_short_title") + MIN_TOPIC_LEN); // "您输入的主题内容太短了,最短不能少于" + MIN_TOPIC_LEN);
        if (length > MAX_TOPIC_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_large_title") + MAX_TOPIC_LEN); // "您输入的主题内容太长了,最长不能超过" + MAX_TOPIC_LEN);
        if (content != null)
            length = content.length();
        if (length < MIN_CONTENT_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_short_content") + MIN_CONTENT_LEN);
        if (length > MAX_CONTENT_LEN)
            throw new ErrMsgException(LoadString(request, "err_too_large_content") + MAX_CONTENT_LEN);

        int islocked = 0;

        rootpath = request.getContextPath();

        // 取出被回复的贴子的有关信息
        int recount = 0, layer = 1, orders = 1, parentorders = 1;
        int parentlayer = 1;
        long parentreplyid = -1;
        boolean isroot = false;

        MsgDb msgDd = getMsgDb(replyid);
        if (!msgDd.isLoaded()) {
            throw new ErrMsgException(SkinUtil.LoadString(request, "err_msg_replied_lost")); // "回贴不存在!");
        }

        replyRootName = msgDd.getName();

        recount = msgDd.getRecount();
        parentlayer = msgDd.getLayer();
        layer = parentlayer + 1;
        rootid = msgDd.getRootid();
        if (rootid == -1) { // 当被回复贴为根帖时
            rootid = replyid;
            isroot = true;
        } else
            recount = 0;

        replyRootName = msgDd.getName();
        blog = msgDd.isBlog();

        parentorders = msgDd.getOrders();
        parentreplyid = msgDd.getReplyid();
        islocked = msgDd.getIsLocked();
        if (islocked == 1)
            throw new ErrMsgException(LoadString(request, "err_locked")); // "该贴已被锁定!");

        ResultSet rs = null;
        String sql = "";

        boolean isvalid = true;
        if (!isroot) { // 如果被回贴不是根贴则从根贴中取出回复数
            MsgDb rootmsg = getMsgDb(rootid);
            recount = rootmsg.getRecount();
            islocked = rootmsg.getIsLocked();
            replyRootName = rootmsg.getName();
            blog = rootmsg.isBlog();
        }

        int intIsBlog = blog?1:0;

        Conn conn = new Conn(connname);

        boolean updateorders = true;
        if (isroot && recount == 0)
            orders = parentorders + 1; // 如果是根贴且尚未有回贴,则orders=parentorders=1;
        else {
            if (parentreplyid == -1) { // 父结点为根贴
                orders = recount + 2;
                updateorders = false;
            } else {
                // 取出被回贴的下一个兄弟结点或当无兄弟结点时取最靠近的layer较小的结点的orders
                sql = "select min(orders) from sq_message where orders>" +
                      parentorders +
                      " and msg_layer<=" + parentlayer;
                try {
                    rs = conn.executeQuery(sql);
                    if (rs != null && rs.next())
                        orders = rs.getInt(1); // 如果orders=0,则表示未搜索到符合条件的贴子,回贴是位于最后的一个节点
                } catch (SQLException e) {
                    isvalid = false;
                    Logger.getLogger(MsgDb.class.getName()).error("AddReply SQLexception: " + e.getMessage());
                    throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.ERR_DB));
                } finally {
                    try {
                        if (rs != null)
                            rs.close();
                    } catch (Exception e) {}
                    if (!isvalid && conn != null) {
                        conn.close();
                        conn = null;
                    }
                }
                if (orders == 0) {
                    updateorders = false;
                    orders = recount + 2;
                }
            }
        }

        recount++;

        id = SequenceMgr.nextID();

        String virtualpath = "";

        FileInfo fi = null;
        Vector v = fu.getFiles();
        int size = v.size();
        String[] fileNameAry = null;
        if (size > 0) {
            fi = (FileInfo) v.get(0);
            // 为每个附件生成文件名
            fileNameAry = new String[size];
            for (int i=0; i<size; i++) {
                fileNameAry[i] = FileUpload.getRandName() + "." + ((FileInfo)v.get(i)).getExt();
            }
        }

        int msgType = TYPE_MSG;

        if (ret == FileUpload.RET_SUCCESS && fi!=null) {
            extName = fi.getExt();
            Calendar cal = Calendar.getInstance();
            String year = "" + (cal.get(cal.YEAR));
            String month = "" + (cal.get(cal.MONTH) + 1);
            String filepath = Global.getRealPath() + "forum/upfile/" +
                              year + "/" + month + "/";
            File f = new File(filepath);
            if (!f.isDirectory()) {
                f.mkdirs();
            }
            virtualpath = "upfile/" + year + "/" + month;
            fu.setSavePath(filepath); // 设置保存的目录

            picturename = fileNameAry[0];
            picturename = virtualpath + "/" + picturename;

            Iterator ir = v.iterator();
            int k = 0;
            while (ir.hasNext()) {
                fi = (FileInfo) ir.next();
                extName = fi.getExt();
                String ubbtype = "";
                if (extName.equalsIgnoreCase("gif") ||
                    extName.equalsIgnoreCase("jpg") ||
                    extName.equalsIgnoreCase("png") || extName.equalsIgnoreCase("bmp"))
                    ubbtype = "img";
                else if (extName.equalsIgnoreCase("swf"))
                    ubbtype = "flash";
                else
                    ubbtype = "URL";

                if (isWebedit >= WEBEDIT_REDMOON) {
                    if (ubbtype.equals("img"))
                        content = "<BR><a onfocus=this.blur() href=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" target=_blank><IMG SRC=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" border=0 alt=" + SkinUtil.LoadString(request, "res.cn.js.fan.util.StrUtil", "click_open_win") + " onmousewheel='return zoomimg(this)' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a><BR>" + content;

                    else if (ubbtype.equals("flash"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" +
                                  ubbtype + "]\n" + content;
                } else {
                    if (ubbtype.equals("img"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" + ubbtype + "]\n" +
                                  content;
                    else if (ubbtype.equals("flash"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" +
      

⌨️ 快捷键说明

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