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

📄 defaultrender.java~65~

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA~65~
字号:
package com.redmoon.forum.plugin;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import cn.js.fan.util.*;
import cn.js.fan.web.Global;
import cn.js.fan.web.SkinUtil;
import com.redmoon.forum.*;
import com.redmoon.forum.person.UserDb;
import com.redmoon.forum.plugin.base.IPluginRender;
import org.apache.log4j.Logger;
import com.redmoon.forum.plugin.base.IPluginScore;

public class DefaultRender implements IPluginRender {
    static Logger logger = Logger.getLogger(DefaultRender.class.getName());

    public DefaultRender() {
    }

    public String RenderVote(HttpServletRequest request, MsgDb md) {
        UserDb user = new UserDb();
        user = user.getUser(md.getName());
        if (user.isValid())
            return md.getVoteOption();
        else
            return null;
    }

    public String RenderContent(HttpServletRequest request, MsgDb md) {
        return doRendContent(request, md);
    }

    public String doRendContent(HttpServletRequest request, MsgDb md) {
        UserDb user = new UserDb();
        user = user.getUser(md.getName());
        if (!user.isValid()) {
            showAttachment = false;
            return
                    "=======================\n\n该用户的所有言论均已被屏蔽!\n\n=======================";
        }
        String content = md.getContent();
        Privilege privilege = new Privilege();
        String seeUserName = privilege.getUser(request);
        UserDb seeUser = user.getUser(seeUserName);
        // 如果是UBB的格式
        if (md.getIsWebedit() == md.WEBEDIT_UBB) {
            content = StrUtil.toHtml(content);
            // UBB代码处理
            if (md.getShowUbbcode() == 1) {
                if (md.getShowSmile() == 1) {
                    content = StrUtil.ubb(content, true);
                } else
                    content = StrUtil.ubb(content, false);
            }
        }
        else {
            content = StrUtil.ubbWithoutAutoLink(content);
        }

        String subStr = "===== 以下为隐藏信息 回帖后才能显示 =====";
        String subStrExp = "===== 以下为隐藏信息 经验值高于$e时才能显示 =====";

        String patternStr = "";
        Pattern pattern;
        Matcher matcher;
        // 处理回复可见, 如果是管理员,则可见
        boolean canEdit = false;
        try {
            canEdit = privilege.canEdit(request, md);
        }
        catch (ErrMsgException e) {
            logger.info("RenderContent:" + e.getMessage());
        }
        if (canEdit) {
            content = StrUtil.replyCanSee(content, true, subStr);
        } else {
            patternStr = "(\\[REPLY\\])(.[^\\[]*)(\\[\\/REPLY\\])";
            pattern = Pattern.compile(patternStr,
                                      Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
            matcher = pattern.matcher(content);
            // 如果存在有限制回复可见的UBB代码
            if (matcher.find()) {
                boolean canSee = false;
                // 如果是根贴
                if (md.getReplyid()==-1)
                    canSee = md.isUserReplyerOfMsg(seeUserName);
                else { // 如果是回贴
                    long rootid = md.getRootid();
                    MsgDb rootMsg = md.getMsgDb(rootid);
                    canSee = rootMsg.isUserReplyerOfMsg(seeUserName);
                }
                if (canSee) {
                    content = matcher.replaceAll(subStr + "<BR>" + "$2");
                }
                else {
                    content = matcher.replaceAll(subStr);
                    showAttachment = false;
                }
            }
        }

        // 处理经验值高于某值时可见
        patternStr = "(\\[HIDE_EXP=([0-9]*)\\])(.[^\\[]*)(\\[\\/HIDE_EXP\\])";
        pattern = Pattern.compile(patternStr,
                                  Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(content);
        // 如果存在有限制经验值可见的UBB代码
        if (matcher.find()) {
            String exp = "";
                exp = matcher.group(2);
                if (!StrUtil.isNumeric(exp))
                    exp = "0";
            subStrExp = subStrExp.replaceFirst("\\$e", exp);
            if (canEdit)
                content = StrUtil.experienceCanSee(content, true, subStrExp);
            else {
                int e = seeUser.getExperience();
                int iexp = Integer.parseInt(exp);
                boolean canSee = e>=iexp?true:false;
                if (canSee) {
                    content = matcher.replaceAll(subStrExp + "<BR>" + "$3");
                }
                else {
                    content = matcher.replaceAll(subStrExp);
                    showAttachment = false;
                }
            }
        }

        String subStrPoint = "===== 以下为隐藏信息 需付费 $f $e $w 才能查看 =====";
        patternStr =
                "(\\[point=([a-z|A-Z]*),\\s*([0-9]*)\\])(.[^\\[]*)(\\[\\/point\\])";
        pattern = Pattern.compile(patternStr,
                                  Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(content);
        if (matcher.find()) {
            String moneyCode = matcher.group(2);
            String strsum = matcher.group(3);
            int sum = 0;
            String usePoint = ParamUtil.get(request, "usePoint");
            try {
                sum = StrUtil.toInt(strsum);
            }
            catch (Exception e) {
                logger.info("doRenderContent:" + e.getMessage());
            }
            ScoreMgr sm = new ScoreMgr();
            ScoreUnit su = sm.getScoreUnit(moneyCode);

            subStrPoint = subStrPoint.replaceFirst("\\$f", "" + su.getName());
            subStrPoint = subStrPoint.replaceFirst("\\$e", "" + sum);
            subStrPoint = subStrPoint.replaceFirst("\\$w", su.getDanWei());

            boolean canSee = canEdit;
            String reason = "";
            String info = "";
            // 付费查看
            if (usePoint.equals("true")) {
                // 检查用户是否已登录
                if (!privilege.isUserLogin(request)) {
                    canSee = false;
                    reason = "请先登录";
                } else {
                    IPluginScore isc = su.getScore();
                    if (isc != null) {
                        try {
                            isc.pay(seeUserName, isc.SELLER_SYSTEM, sum);
                            info += "<BR><BR><font color=red>您已使用了 " + su.getName() + sum + su.getDanWei() + " 您的余额为:" + isc.getUserSum(seeUserName) + "</font>";
                            canSee = true;
                        } catch (ErrMsgException e) {
                            reason = e.getMessage();
                            canSee = false;
                        }
                    } else {
                        canSee = false;
                    }
                }
            }

            if (!canSee) {
                String action = "[<a href='#' onClick=\"if (window.confirm('您确定要付费查看吗?')) window.location.href='showtopictree.jsp?" + "rootid=" + md.getRootid() + "&showid=" + md.getId() + "&usePoint=true'\">点击付费查看</a>]";
                action += "<BR><BR><font color=red>" + reason + "</font>";
                content = matcher.replaceFirst(subStrPoint + "<BR>" + action);
                showAttachment = false;
            }
            else  {
                content = matcher.replaceFirst(subStrPoint + "<BR>" + "$4" + info);
            }
        }

        String subStrPayme = "===== 以下为隐藏信息 需付费给 $u $f $e $w 才能查看 =====";

        patternStr =
                "(\\[payme=([a-z|A-Z]*),\\s*([0-9]*)\\])(.[^\\[]*)(\\[\\/payme\\])";
        pattern = Pattern.compile(patternStr,
                                  Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(content);
        if (matcher.find()) {
            String moneyCode = matcher.group(2);
            String strsum = matcher.group(3);
            int sum = 0;
            String payme = ParamUtil.get(request, "payme");
            try {
                sum = StrUtil.toInt(strsum);
            } catch (Exception e) {
                logger.info("doRenderContent:" + e.getMessage());
            }
            ScoreMgr sm = new ScoreMgr();
            ScoreUnit su = sm.getScoreUnit(moneyCode);

            subStrPayme = subStrPayme.replaceFirst("\\$f", "" + su.getName());
            subStrPayme = subStrPayme.replaceFirst("\\$e", "" + sum);
            subStrPayme = subStrPayme.replaceFirst("\\$w", su.getDanWei());

            boolean canSee = canEdit;
            String reason = "";
            String info = "";
            // 付费查看
            if (payme.equals("true")) {
                // 检查用户是否已登录
                if (!privilege.isUserLogin(request)) {
                    canSee = false;
                    reason = "请先登录";
                } else {
                    IPluginScore isc = su.getScore();
                    if (isc != null) {
                        try {
                            isc.pay(seeUserName, isc.SELLER_SYSTEM, sum);
                            info += "<BR><BR><font color=red>您支付给 " + su.getName() +
                                    sum + su.getDanWei() + " 您的余额为:" +
                                    isc.getUserSum(seeUserName) + "</font>";
                            canSee = true;
                        } catch (ErrMsgException e) {
                            reason = e.getMessage();
                            canSee = false;
                        }
                    } else {
                        canSee = false;
                    }
                }
            }

            if (!canSee) {
                String action = "[<a href='#' onClick=\"if (window.confirm('您确定要支付给费用查看吗?')) window.location.href='showtopictree.jsp?" +
                                "rootid=" + md.getRootid() + "&showid=" + md.getId() +
                                "&payme=true'\">点击付费查看</a>]";
                action += "<BR><BR><font color=red>" + reason + "</font>";
                content = matcher.replaceFirst(subStrPayme + "<BR>" + action);
                showAttachment = false;
            } else {
                content = matcher.replaceFirst(subStrPayme + "<BR>" + "$4" + info);
            }
        }
        return content;
    }

    public String RenderAttachment(HttpServletRequest request, MsgDb md) {
        if (!showAttachment) {
            return "";
        }
        // if (md.getIsWebedit() == md.WEBEDIT_REDMOON) {
            if (md != null) {
                java.util.Vector attachments = md.
                                               getAttachments();
                java.util.Iterator ir = attachments.
                                        iterator();
                String str = "";
                while (ir.hasNext()) {
                    Attachment am = (Attachment)
                                    ir.next();
                    str +=
                            "<table width='90%'  border='0' cellspacing='0' cellpadding='0'>";
                    str += "  <tr>";
                    str +=
                            "    <td height=40 align='left'><img src='" + Global.getRootPath() + "/netdisk/images/" + am.getIcon() + "'>";
                    str +=
                            "    &nbsp; <a target=_blank href='getfile.jsp?msgId=" + am.getMsgId() + "&attachId=" + am.getId() +
                            "'>" + am.getName() +
                          "</a> (" + DateUtil.format(am.getUploadDate(), "yyyy-MM-dd HH:mm") + ", &nbsp;" + NumberUtil.round((double)am.getSize()/1024000, 3) + "&nbsp;M)";
                    String str1 = SkinUtil.LoadString(request, "info_attach_download_count").replaceFirst("\\$count", ""+am.getDownloadCount());
                    str += str1;
                    str += "</td>";
                    str += "  </tr>";
                    str += "</table>";
                }
                return str;
            }
        // }

        return "";
    }

    public void setShowAttachment(boolean showAttachment) {
        this.showAttachment = showAttachment;
    }

    public boolean isShowAttachment() {
        return showAttachment;
    }

    private boolean showAttachment = true;

}

⌨️ 快捷键说明

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