/*
* Created on 2007-3-22
* Last modified on 2007-12-14
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.view.util;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.yeqiangwei.club.module.music.service.ConfigService;
import com.yeqiangwei.club.param.FavoriteParameter;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.forum.FavoriteForumService;
import com.yeqiangwei.club.service.forum.ForumService;
import com.yeqiangwei.club.model.FavoriteForum;
import com.yeqiangwei.club.model.Forum;
import com.yeqiangwei.club.model.Reply;
import com.yeqiangwei.club.service.security.UserPower;
import com.yeqiangwei.club.service.topic.ReplyService;
import com.yeqiangwei.club.service.user.UserLogin;
import com.yeqiangwei.club.service.util.BasicInfoService;
import com.yeqiangwei.club.service.util.NoAllowedCharService;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.view.model.ForumLabelView;
import com.yeqiangwei.club.view.model.ForumView;
import com.yeqiangwei.club.view.model.ReplyView;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.club.view.model.UserView;
import com.yeqiangwei.html.OutPrint;
import com.yeqiangwei.util.FormatDateTime;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;
public class ViewCoder {
private static UserPower USER_POWER;
public static String getRuleElement(double d){
if(d>0){
return "+"+d;
}else{
return String.valueOf(d);
}
}
public static String getRuleElement(int d){
if(d>0){
return "+"+d;
}else{
return String.valueOf(d);
}
}
public static String signaturesFilter(String str){
str = StringHelper.htmlEncoder(str); //过滤为安全字符
str = EnCoder.simpleTag(str);
str = EnCoder.ubbPattern(str, "\\[bg=(.*?)\\](.*?)\\[/bg\\]","<span style=\"$1\">$2</span>");
//str = EnCoder.ubbPattern(str,"\\[move\\](.*?)\\[/move\\]","<marquee scrollamount=\"3\" delay=\"3\" direction=\"left\" onmouseout='start()' onmouseover='stop()'>$1</marquee>");
str = EnCoder.ubbPattern(str,"\\[fly\\](.*?)\\[/fly\\]","<marquee scrollamount=\"3\" delay=\"3\" direction=\"left\" onmouseout='start()' onmouseover='stop()'>$1</marquee>");
return str;
}
public static String getStorey(int storey){
StringBuffer sb = new StringBuffer();
switch(storey){
case 0:
sb.append("楼主");
break;
case 1:
sb.append("沙发");
break;
case 2:
sb.append("板凳");
break;
case 3:
sb.append("地板");
break;
default:
sb.append(storey);
sb.append("楼");
break;
}
return sb.toString();
}
public static String copyright(byte b){
StringBuffer sb = new StringBuffer();
sb.append("<div class=\"copyright\">");
switch(b){
case 1:
sb.append("作者声明:该文版权归作者个人所有,");
sb.append(getBasicInfoService().findOnly().getName());
sb.append("享有网络发表权,其他网站、媒体未经书面许可,不得以任何形式转载!");
break;
case 2:
sb.append("作者声明:该文版权为网络共享,大家喜欢的话可以任意转载,传抄,谢绝传统媒体转载!");
break;
case 3:
sb.append("作者声明:该文在未经商业用途的情况下,可任意转载,传抄……");
break;
}
sb.append("</div>");
return sb.toString();
}
public static String favoriteForum(HttpServletRequest request, ForumView forum){
StringBuffer sb = new StringBuffer("");
int forumId = 0;
if(!Validator.isEmpty(forum)){
forumId = forum.getForumId();
}else{
forumId = ParamUtils.getIntParameter(request,"forumId");
}
FavoriteParameter param = new FavoriteParameter();
param.setForumId(forumId);
long i = ViewCoder.getFavoriteForumService().countByParameter(param);
FavoriteForum model = getFavoriteForumService().findOnlyByUserIdAndForumId(UserLogin.getUserId(request),forumId);
if(!Validator.isEmpty(model)){
sb.append("<a href=\"/club/favoriteTopic.jsp\">您已订阅</a>");
}else{
sb.append("<a href=\"forum.do?act=doFavorite&forumId=");
sb.append(forumId);
sb.append("\">订阅本版</a>");
}
if(i==0){
sb.append("<span class=\"gray\">(<a href=\"favoriteForum.jsp?forumId="+forumId+"\">暂无人订阅</a>)</span>");
}else{
sb.append("<span class=\"gray\">(<a href=\"favoriteForum.jsp?forumId="+forumId+"\">已有");
sb.append(i);
sb.append("人订阅</a>)</span>");
}
return sb.toString();
}
public static String photo(HttpServletRequest request, UserView user, String rel){
StringBuffer sb = new StringBuffer();
if(!Validator.isEmpty(user)){
sb.append("<a href=\"");
sb.append(UrlUtils.getUrl(UrlUtils.USER,user.getUserId(),0,request));
if(Validator.isEmpty(rel)){
sb.append("\">");
}else{
sb.append("\" "+rel+">");
}
if(!Validator.isEmpty(user.getPhoto())){
sb.append("<img src=\"");
sb.append(user.getPhoto());
sb.append("\" alt=\""+user.getUserName()+"\"/>");
}else{
sb.append("<img src=\"/club/images/nophoto.gif\" alt=\""+user.getUserName()+"暂无头像\"/>");
}
sb.append("</a>");
}else{
sb.append("<img src=\"/club/images/nophoto.gif\" alt=\"\"/>");
}
return sb.toString();
}
public static String userMenu(HttpServletRequest request, UserView user, String defaultStr){
//String uri = request.getRequestURI();
if(!Validator.isEmpty(user)&&user.getUserId()>0){
StringBuffer sb = new StringBuffer();
sb.append("<a href=\"");
sb.append(UrlUtils.getUrl(UrlUtils.USER,user.getUserId(),0,request));
sb.append("\">");
sb.append(user.getUserName());
sb.append("</a>");
sb.append("<span class=\"umenu\"><span");
sb.append(" onmouseover=\"uu.menu(this.parentNode,");
sb.append(user.getUserId());
sb.append(",'");
sb.append(user.getUserName());
sb.append("'");
/*
if(!uri.equals("/club/thread.jsp")
&&!uri.equals("/club/favoriteForum.jsp")
&&!uri.equals("/club/friend.jsp")
){
sb.append(",'");
sb.append(user.getPhoto());
sb.append("'");
}
else{
sb.append(",''");
}
*/
sb.append(",'");
sb.append(user.getPhoto());
sb.append("'");
sb.append(",'");
sb.append(user.getCredit());
sb.append(",");
sb.append(user.getScore());
sb.append(",");
sb.append(user.getMoney());
sb.append(",");
sb.append(user.getViews());
sb.append("'");
sb.append(",'最近到访:");
sb.append(OutPrint.isDateHtml(user.getLastLoginDateTime()).replaceAll("<(.*?)>", ""));
sb.append("'");
sb.append(");\"");
sb.append(">");
sb.append(" ");
/*
sb.append("<img name=\"mlist\" src=\"/club/images/mlist.gif\" align=\"absmiddle\" border=\"0\" alt=\"展开(");
sb.append(user.getUserName());
sb.append(")的相关操作\"/>");
*/
sb.append("</span></span>");
return sb.toString();
}else{
return defaultStr;
}
}
/**
*
* @param content
* @param isDeleted 逻辑删除
* @param power 强行浏览
* @return
*/
public static String getContent(HttpServletRequest request, int forumId, String content, boolean isDeleted, boolean escapeXml)
{
if(isDeleted&&!ViewCoder.getUserPower().canAccess(request,UserPower.ADMINPOWER,1)/*查看删帖权限*/){
content = "<font class=\"del\">该帖已被删除!</font>";
}
//else if(!ViewCoder.getUse