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

📄 topicdao.java

📁 EasyJForum 是一个基于 Java 技术的免费社区论坛软件系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                stmtQuery = conn.createStatement();
                rs = stmtQuery.executeQuery("CALL IDENTITY()");
            }

            if (rs.next())
            {
                result = rs.getInt(1);

                CacheManager cache = CacheManager.getInstance();
                BoardVO aBoard = cache.getBoard(sectionID, boardID);
                
                synchronized(aBoard)
                {
                    aBoard.topics = aBoard.topics + 1;
                    aBoard.todayPosts = aBoard.todayPosts + 1;
                    aBoard.lastTopicUser = userID;
                    aBoard.lastNickname = nickname;
                    aBoard.lastTopicID = String.valueOf(result);
                    aBoard.lastTopicTitle = subject;
                    aBoard.lastTopicTime = AppUtils.getCurrentTimeStr();
                }
            }
            return result;
        }
        finally
        {
            dbManager.closeResultSet(rs);
            dbManager.closeStatement(stmtQuery);
            dbManager.closePStatement(pstmtInsert);
        }
    }

    public String updateTopic(HttpServletRequest request, UserInfo userinfo,
                              String topicID, SectionVO aSection, BoardVO aBoard,
                              GroupVO aGroup) throws Exception
    {
        String result = null;
        ArrayList<UploadVO> attaches = null;
        try
        {
            attaches = MyFileUpload.getInstance().upload(request);
        }
        catch(SizeLimitExceededException e)
        {
            return "上传附件时出错:文件大小超过限制,允许的最大值为:" 
                    + ((SizeLimitExceededException)e).getPermittedSize() + " 字节。";
        }
        catch(Exception e)
        {
            return "上传附件时出错:" + e.getMessage();
        }
        
        String subject = PageUtils.decodeParam((String)request.getAttribute("subject"));
        subject = subject.replace("<", "&lt;");
        subject = subject.replace(">", "&gt;");

        StringBuilder badwords = new StringBuilder();
        subject = this.censorWords(subject, badwords);
        
        int attachCount = 0;
        if (attaches != null)
            attachCount = attaches.size();
        if (attachCount > 0 && 
                !PageUtils.isPermitted(aBoard,aGroup,IConstants.PERMIT_UPLOAD))
        {
            return "您没有上传附件的权限";
        }
        
        String content = validateContent(request, aGroup, aSection, aBoard,
                                         attaches, badwords); 
        
        // Check if attach image or flash has already been inserted
        String forumURL = PageUtils.getForumURL(request);
        String rootPath = PageUtils.getRootPath(request.getRequestURL().toString());
        String uploadURL = this.getAbsoluteURL("./upload/", forumURL, rootPath);
        
        if (attaches != null)
        {
            UploadVO aAttach = null;
            for (int i=attaches.size()-1; i>=0; i--)
            {
                aAttach = (UploadVO)attaches.get(i);
                if (aAttach.attachID != null && aAttach.attachID.length() > 0)
                {
                    if (aAttach.state == 'N' 
                        && content.indexOf("src=\"" + uploadURL + aAttach.localname) > 0)
                    {
                        if (aAttach.localname.toLowerCase().indexOf(".swf") > 0)
                            aAttach.state = 'F';
                        else
                            aAttach.state = 'I';
                    }
                }
            }
        }
        
        Connection conn = dbManager.getConnection();
        try
        {
            conn.setAutoCommit(false);

            String attachIcon = null;
            if (attaches != null)
                attachIcon = this.getAttachIcon(attaches);
            if (attachIcon == null)
                attachIcon = "";
            
            if (attachIcon.indexOf('I') < 0)
            {            
                Object picAttr = request.getAttribute("pic");
                if (picAttr != null && picAttr.toString().equals("1"))
                    attachIcon = attachIcon + 'I';
            }
            if (attachIcon.indexOf('F') < 0)
            {            
                Object flashAttr = request.getAttribute("flv");
                if (flashAttr != null && flashAttr.toString().equals("1"))
                    attachIcon = attachIcon + 'F';
            }
            
            updateTopic(request, userinfo, topicID, subject, content, attachCount, attachIcon, conn);

            String postUserID = (String)request.getAttribute("postuser");
            int totalCredits = 0;
            
            if (attachCount >= 0)  // if deleted all attachments, attachCount = 0
            {
                AttachDAO.getInstance()
                         .updateAttaches(attaches, postUserID, topicID, "0", conn);
                
                int credits = ForumSetting.getInstance().getInt(ForumSetting.CREDITS, "upload");
                if (credits > 0)
                {
                    String oldCount = 
                        (String)request.getSession().getAttribute("attachCount");
                    // attachCount = attaches.size();
                    if (oldCount != null)
                        attachCount = attachCount - Integer.valueOf(oldCount);
                    totalCredits = credits * attachCount;
                }
            }
            
            String userID = (userinfo == null ? "" : userinfo.userID);
            if (totalCredits != 0 && userID.length() > 0 && userID.equalsIgnoreCase(postUserID))
            {
                ArrayList<Object> paramValues = new ArrayList<Object>();
                paramValues.add(totalCredits);
                paramValues.add(userID);
                this.execUpdateSql(adapter.User_IncCredits, paramValues, conn);
    
                if (userinfo != null)
                    userinfo.credits = userinfo.credits + totalCredits;
            }

            if (badwords.length() > 1)
            {
                ActionLogDAO.getInstance().addCensorLog(
                        userID, aBoard.boardID, aBoard.boardName, topicID, subject,
                        "0", badwords.toString(), conn);
            }
                
            if (userID.length() > 0 && !userID.equalsIgnoreCase(postUserID))
            {
                // Add moderator log
                String[] topicIds = new String[1];
                String[] topicTitles = new String[1];
                String[] boardIds = new String[1];
                String[] boardNames = new String[1];

                topicIds[0] = topicID;
                topicTitles[0] = subject;
    
                boardIds[0] = aBoard.boardID;
                boardNames[0] = aBoard.boardName;
                
                ActionLogDAO.getInstance().addModerateLog(
                                request, boardIds, boardNames, topicIds, topicTitles,
                                "0", "编辑主题", "", conn);
            }
            
            conn.commit();
            result = "OK";
        }
        catch(Exception e)
        {
            conn.rollback();
            throw e;
        }
        finally
        {
            dbManager.closeConnection(conn);
        }
        return result;
    }

    /**
     * Update a forum topic
     * @param 
     *      request - HttpServletRequest
     *      userID - User ID
     *      attachCount - Attachment count
     *      conn - DB Connection
     * @return Topic ID
     * @throws SQLException
     * @since 1.0
     */
    private void updateTopic(HttpServletRequest request, UserInfo userinfo, String topicID,    
                             String subject, String content, int attachCount,  
                             String attachIcon, Connection conn) throws SQLException
    {
        PreparedStatement pstmtUpdate = null;
        try
        {
            int iReward = 0;
            String reward = PageUtils.decodeParam((String)request.getAttribute("reward"));
            if (reward.length() > 0)
            {
                try
                {
                    iReward = Integer.parseInt(reward);
                }
                catch(Exception e){ /* Ignored */ }
            }

            String isHidePost = (String)request.getAttribute("isHidePost");
            if (isHidePost == null || isHidePost.length() == 0)
                isHidePost = "F";

            String isTopPost = (String)request.getAttribute("isTopPost");
            if (isTopPost == null || isTopPost.length() == 0)
                isTopPost = "F";

            String isReplyNotice = (String)request.getAttribute("isReplyNotice");
            if (isReplyNotice == null || isReplyNotice.length() == 0)
                isReplyNotice = "F";
            
            String userID = (userinfo == null ? "" : userinfo.userID);
            
            pstmtUpdate = conn.prepareStatement(adapter.Topic_Update);
            pstmtUpdate.setInt(1, iReward);
            pstmtUpdate.setString(2, subject);
            pstmtUpdate.setString(3, content);
            pstmtUpdate.setString(4, isReplyNotice);
            pstmtUpdate.setString(5, isHidePost);
            pstmtUpdate.setInt(6, attachCount);
            pstmtUpdate.setString(7, attachIcon);

            if (isTopPost.charAt(0) == 'T')
                pstmtUpdate.setString(8, "3");
            else
                pstmtUpdate.setString(8, "N");
            
            pstmtUpdate.setString(9, userID);
            pstmtUpdate.setString(10, topicID);
            pstmtUpdate.executeUpdate();
            
            String userPostIDs = (String)request.getSession().getAttribute("userPostIDs");
            if (userPostIDs != null && userPostIDs.indexOf(topicID) >= 0 
                    && userinfo != null)
            {
                ArrayList<Object> paramValues = new ArrayList<Object>();
                paramValues.add(userinfo.nickname);
                paramValues.add(topicID);
                this.execUpdateSql(adapter.Topic_ModNickname, paramValues, conn);
            }            
        }
        finally
        {
            dbManager.closePStatement(pstmtUpdate);
        }
    }

    // Censor bad words
    public String censorWords(String text, StringBuilder badwords)
    {
        String result = text;
        OptionVO[] words = ForumSetting.getInstance().getCensorWords();
        if (words != null && words.length > 0)
        {
            String goodWord = null;
            for (int i=0; i<words.length; i++)
            {
                if (words[i].name.length() == 0) continue;
                if (result.indexOf(words[i].name) < 0) continue;
                
                goodWord = words[i].value;
                if (goodWord == null)
                {
                    result = result.replace(words[i].name, "**");
                    badwords.append(words[i].name).append(' ');
                }
                else if (goodWord.equals("{CHECK}"))
                {
                    badwords.append(words[i].name).append('=').append("{CHECK}").append(' ');
                }
                else
                {
                    result = result.replace(words[i].name, goodWord);
                    badwords.append(words[i].name).append('=').append(goodWord).append(' ');
                }
            }
        }
        return result;
    }
    
    public String validateContent(HttpServletRequest request, GroupVO aGroup,
                                  SectionVO aSection, BoardVO aBoard,
                                  ArrayList<UploadVO> attaches, StringBuilder badwords)
    {
        String result = PageUtils.decodeParam((String)request.getAttribute("content"));
        result = this.censorWords(result, badwords);

        // Filt script, iframe, object within HTML content
        boolean allowHTML = aGroup.rights.indexOf(IConstants.PERMIT_USE_HTML) >= 0;
        if (!allowHTML)
        {
            result = script_pattern.matcher(result).replaceAll("");
            result = iframe_pattern.matcher(result).replaceAll("");
            result = object_pattern.matcher(result).replaceAll("");
        }

        Matcher m = null;
        StringBuffer sb = null;                    
        String url = null;

        String forumURL = PageUtils.getForumURL(request);
        String rootPath = PageUtils.getRootPath(request.getRequestURL().toString());
        
        String isBBCodeOff = PageUtils.decodeParam((String)request.getAttribute("bbcodeoff"));
        if (isBBCodeOff.equals("yes"))
        {
            StringBuilder sbuf = new StringBuilder(result);
            replaceHTMLStr(sbuf, "[", "\u005B");
            replaceHTMLStr(sbuf, "]", "\u005D");
            result = sbuf.toString();
        }
        else
        {
            StringBuilder tagBuf = null; 
            // Filt image
            if (aBoard.isImageOK=='T')
            {
                sb = null;
                String title = null;

⌨️ 快捷键说明

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