<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Conn.asp"-->
<!--#include file="Ex_Cls/Ex_SkinCls.asp"-->
<!--#include file="Ex_Cls/Ex_ImgCls.asp"-->
<%response.buffer=true%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>易心博客-模板</title>
</head>
<link href="Admin_STYLE.CSS" rel="stylesheet" type="text/css"> 
<script src="wbTextBox/kindeditor.js"></script>
<body>
<script language="JavaScript">
//用户自定义函数---检测表单填写
function check1()
{ 
  var topic=document.getElementById("topic");
  var author=document.getElementById("author");
  var body=KE.util.getData('Body');
  if (topic.value=="" || author.value=="" || body.value=="")
  {
	alert("请把信息填写完整");
	return false;
  }
}
function check2()
{
	var body=KE.util.getData('Body');
  if (body.value=="")
  {
	alert("请把信息填写完整");
	body.focus();
	return false;
  }
}
</script>
<%
Dim ExComm,ExFso
Set ExComm=new Ex_CommonCls
Set ExFso=new Ex_FsoCls
ExComm.IsAdLogin 
ExComm.IsIpAllow
Dim Action
  Action=Request.QueryString("action")
  select case Action
  Case "addform1"
       AddForm1()'添加主模板表单
  Case "add1"'
	   Add1()'添加主模板过程
  Case "addform2"'
       AddForm2()' 添加辅模板表单
  Case "add2"
       Add2()'添加辅模板过程
  Case "changeform1"'
	   ChangeForm1()'修改主模板表单
  Case "change1"
	   Change1()'修改主模板过程
  Case "changeform2"'
       ChangeForm2()'修改辅模板表单
  Case "change2"
	   Change2()'修改辅模板过程
  case "del"
       Del()
  Case "show"
	   Show()
  case "set"
		SetDefault()
  Case "addbaiduform"
	   AddBaiduForm
  Case "addbaidu"
       AddBaidu()
  End Select 
 '编码转换
Function BytesToBstr(ByVal strBody,CodeBase)
       dim obj
       set obj=Server.CreateObject("Adodb.S"&"tr"&"eam")
       obj.Type=1
       obj.Mode=3
       obj.Open
       obj.Write strBody
       obj.Position=0
       obj.Type=2
       obj.Charset=CodeBase
       BytesToBstr=obj.ReadText
       obj.Close
       set obj=nothing
End Function
'添加百度风格
  Sub AddBaidu()
	Dim xmlHttp,CssCnt,CssUrl,ExImg,Baidu,Re,Matchs,Match,Temp
	'On Error Resume Next 
	Baidu=Trim(Request.Form("baiduhi"))
	set xmlHttp=server.createobject("M"&"i"&"cr"&"o"&"s"&"of"&"t."&"X"&"M"&"LH"&"TT"&"P")
	xmlHttp.open "get",Baidu,False 
	xmlHttp.send()
	If xmlHttp.readystate<>4 Then
		xmlHttp.waitforresponse 150
	End If
	if xmlHttp.readystate<>4 then
		ExComm.ShowMsg "风格加载失败,可能是空间原因导致.建议使用易心空间.",""
	end if
	Temp=xmlHttp.ResponseBody
	Temp=BytesToBstr(Temp,"gb2312")
	Baidu=Replace(Baidu,"http://hi.baidu.com/","")
	If InStr(Baidu,"/")<>0 Then 
		Baidu=Split(Baidu,"/")(0)
	End If 
	Baidu=Replace(Baidu,"%","")
	Set Re=new Regexp
	Re.Global=True   
	Re.Multiline=True
	Re.IgnoreCase=True 
	Re.Pattern="<link rel=""stylesheet"" type=""text/css"" href=""/(.*?)\.css"
	Set Matchs=Re.Execute(Temp)
	For Each Match In Matchs
		CssUrl=Match.Value
		CssUrl=Replace(CssUrl,"<link rel=""stylesheet"" type=""text/css"" href=""/","")
		CssUrl="http://hi.baidu.com/"&CssUrl
		xmlHttp.open "get",CssUrl,false
		xmlHttp.send
		Temp=BytesToBstr(xmlHttp.ResponseBody,"gb2312")
		If InStr(CssUrl,"/css/item/")<>0 Then 
			Set ExImg=new Ex_ImgCls
			ExImg.imgPath="ExSkin\BaiduSkin\"&Baidu&"\Images"
			ExFso.CreateRoute ExImg.imgPath
			Temp=ExImg.ReplaceUrl(Temp)
			Temp=Replace(Temp,ExImg.imgPath&"\","Images/") 
			ExFso.CreateFile "ExSkin/baiduSkin/"&Baidu&"/ExCss.Css",Temp
		Else
			CssCnt=CssCnt&"/*"&CssUrl&"*/"&vbcrlf&Temp
		End If 
	Next
	ExFso.CreateFile "ExSkin/baiduSkin/"&Baidu&"/Global.Css",CssCnt
	ExComm.ShowMsg "风格添加成功","?action=show"
	Response.End 
  End Sub 
  '删除风格
  Sub Del()
  dim id,strsql
  id=request.querystring("id")
  If id<>"" Then 
	strsql="delete * from Ex_Skin where id="&id
	Conn.execute(strsql)
  Else 
	ExFso.DelFolder(request.querystring("path"))
  End If 
  ExComm.ShowMsg "删除成功",request.servervariables("http_referer")
  response.end 
  end Sub 
Function RefreshTxtSkin
	ExComm.ClearCaches(sn)
	Dim ExSkin
	Set ExSkin=new Ex_SkinCls
	ExSkin.RefreshSkinCache
	Set ExSkin=Nothing 
End Function 
  '设置默认模版
  Sub setdefault()
	dim isdefaultID
	isdefaultID=trim(request("default"))
	Conn.execute("update Ex_Config set DefaultSkin='"&isdefaultID&"'")
	
	RefreshTxtSkin
	ExComm.ShowMsg "修改成功",request.servervariables("http_referer")
	Response.End()
  end Sub
  '添加主模板
  sub add1()
  dim content,mbauthor,topic,strsql,rs
  content=trim(request.Form("Body"))'主模板内容
  mbauthor=request.Form("author")'模板作者
  topic=request.Form("topic")'模板名称
   strsql="select * from Ex_Skin"
   Set rs=server.CreateObject("adodb.recordset")
   rs.open strsql,Conn,1,2
   rs.addnew
   rs("mbauthor")=mbauthor
   rs("topic")=topic
   rs("skin1")=content
   rs.update
   response.redirect("?action=addform2")
  end Sub
  '添加辅模版
  sub add2()
  dim content,strsql,maxid
  content=request.Form("Body")
  strsql="select max(id) from Ex_Skin"
  set maxid=Conn.execute(strsql)
  strsql="update Ex_Skin set skin2='"&content&"' where id="&maxid(0)
  Conn.execute(strsql)
  ExComm.ShowMsg "模板代码添加成功。\n请用ftp软件把模板图片等相关文件上传到博客skin文件夹以完成模板添加。","?action=show"
  response.end
  end Sub
  '修改主模版
  sub change1()
  dim id,content,mbauthor,topic,strsql
  id=request.querystring("id")
  content=Replace(request.form("Body"),"'","''")
  Content=Replace(Content,"onload=''DrawImage(this)''","")
  topic=Replace(request.form("topic"),"'","''")
  mbauthor=Replace(request.form("mbauthor"),"'","''")
  strsql="update Ex_Skin set skin1='"&content&"',topic='"&topic&"',mbauthor='"&mbauthor&"' where id="&id
  Conn.execute(strsql)
  ExComm.ClearCache(sn&"skin1")
  ExComm.ShowMsg "主模板修改成功！！","?action=show"
  response.end
  end Sub
  '修改辅模版
  sub change2()
  dim id,content,strsql
  id=request.querystring("id")
  content=Replace(request.form("Body"),"'","''")
  Content=Replace(Content,"onload=''DrawImage(this)''","")
  strsql="update Ex_Skin set skin2='"&content&"' where id="&id
  Conn.execute(strsql)
  ExComm.ClearCache(sn&"skin1")
  ExComm.ShowMsg "辅模板修改成功!!","?action=show"
  response.end
  end Sub
 %>
<%sub show()
  dim rs,strsql
  strsql="select * from Ex_Skin"
  set rs=Conn.execute(strsql)
  If ExComm.IsCache("DefaultSkin")=False Then 
	ExComm.GetConfigCache("DefaultSkin")
  End If 
  %>
  <center>
<form name="set" method="post" action="?action=set">
 <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
    <tr>
      <th class="topbg" colspan="5">模板设置</th>
    </tr>
    <tr>
      <td colspan="5" style="background:#BCCDEF; text-align:center;">Oblog模板</td>
      </tr>
    <tr>
      <td class="tdbg" width="228"><div align="center">模板名称</div></td>
      <td class="tdbg" width="111"><div align="center">主模板</div></td>
      <td class="tdbg" width="71"><div align="center">辅模板</div></td>
      <td class="tdbg" width="136"><div align="center">删除</div></td>
      <td class="tdbg" width="199"><div align="center">设为默认</div></td>
    </tr>
	<%do while not rs.eof%>
    <tr>
      <td class="tdbg"><div align="center"><%=rs("topic")%></div></td>
      <td class="tdbg"><div align="center"><a href="?action=changeform1&id=<%=rs("id")%>">修改</a></div></td>
      <td class="tdbg"><div align="center"><a href="?action=changeform2&id=<%=rs("id")%>">修改</a></div></td>
      <td class="tdbg"><div align="center"><a href="?action=del&id=<%=rs("id")%>" onClick="return confirm('是否删除?')">删除</a></div></td>
      <td class="tdbg"><div align="center">
	  <%if trim(Application(Sn&"DefaultSkin"))=Trim(Rs("id")) then%>
        <input type="radio" name="default" id="default" value="<%=rs("id")%>" checked>
		<%else%>
		<input type="radio" name="default" id="default" value="<%=rs("id")%>">
		<%end if%>
      </div></td>
    </tr>
<%rs.movenext
loop
%>
<tr>
    <td colspan="5" style="background:#BCCDEF; text-align:center;">其他模板</td>
</tr>
    <tr>
      <td class="tdbg"><div align="center">模板类型</div></td>
      <td colspan="2" class="tdbg"><div align="center">模板名称</div></td>
      <td class="tdbg"><div align="center">删除</div></td>
      <td class="tdbg"><div align="center">设为默认</div></td>
    </tr>
	<%
		Dim ArrSkin,ArrI,ArrM,Template,ArrTemplate
		ArrSkin=ExFso.GetSubFolders("Template")
		If ArrSkin<>"" Then 
			ArrSkin=Split(ArrSkin,"|")
			For ArrI=0 To UBound(ArrSkin)
				ArrTemplate=ExFso.GetSubFolders("ExSkin/"&ArrSkin(ArrI))
				If ArrTemplate<>"" Then 
					ArrTemplate=Split(ArrTemplate,"|")
					For ArrM=0 To UBound(ArrTemplate)
	%>
    <tr>
      <td class="tdbg"><div align="center"><%=ArrSkin(ArrI)%></div></td>
      <td colspan="2" class="tdbg"><div align="center"><%=ArrTemplate(ArrM)%></div></td>
      <td class="tdbg"><div align="center">
	  <a href="?action=del&path=ExSkin/<%=ArrSkin(ArrI)&"/"&ArrTemplate(ArrM)%>" onClick="return confirm('删除后上传的模板文件将在空间中删除.\n是否删除?')">删除</a>
	  </div></td>
      <td class="tdbg"><div align="center">
		<%
			If Application(sn&"DefaultSkin")=ArrSkin(ArrI)&"/"&ArrTemplate(ArrM) Then 
		%>
        <input type="radio" name="default" id="default" value="<%=ArrSkin(ArrI)&"/"&ArrTemplate(ArrM)%>" checked>
		<%
			Else
		%>
		<input type="radio" name="default" id="default" value="<%=ArrSkin(ArrI)&"/"&ArrTemplate(ArrM)%>">
		<%
			End If 
		%>
      </div></td>
    </tr>
	<%
					Next 
				End If 
			Next 
		End If 
	%>
    <tr>
      <td class="tdbg" colspan="5"><div align="center">
        <input type="submit" name="Submit" value="提交">
      </div></td>
    </tr>
  </table>
</form></center>
<br>提示：<br>1.点击右侧的单选按钮选择你要使用的模板，然后点提交按钮。<br>2.如果您的博客采用的是静态模式运行，您还得重新发布所有页面。<br>
<%end Sub
Sub addBaiduForm()%>
<script>
function checkbaidu()
{
	var baidu=document.getElementById("baiduhi").value;
	if (baidu.indexOf("http://hi.baidu.com/")==-1 || baidu=="http://hi.baidu.com/" || baidu=="")
	{
		alert("请填写正确的百度空间地址\n例如:http://hi.baidu.com/jbrose");
		return false;
	}
	baidu=baidu.replace("http://hi.baidu.com/","")
	if (baidu.indexOf("/")!=-1)
	{
		alert("必须填写空间主页地址,并且不要以 / 结尾.\n例如:http://hi.baidu.com/jbrose");
		return false;
	}
}
</script>
<form method="post" action="?Action=addbaidu" onSubmit="return checkbaidu()">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<th class="topbg" colspan="5">添加百度空间风格</th>
<tr>
  <td class="tdbg" align="center">请填写百度空间地址</td>
  <td class="tdbg" align="center"><input name="baiduhi" type="text" size="50" value="http://hi.baidu.com/"></td>
  <td class="tdbg" align="center"><label>
    <input type="submit" name="Submit3" value="添加">
  </label></td>
</tr>
</table>
 </form>
<% End Sub
sub addform1()%><center>
<form name="Dvform" method="post" action="?Action=add1" onSubmit="return check1();">
 <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<th class="topbg" colspan="5">模板添加第一步--添加主模板</th>
<tr>
	<td class="tdbg">模板名称：<font color="red">*</font></td>
	<td class="tdbg"><input name="topic" id="topic"></td>
	<td class="tdbg">作者：<font color="red">*</font></td>
	<td class="tdbg"><input name="author" id="author"></td>
</tr>
<tr>
<td colspan="4" class="tdbg" align="center">
<textarea id="Body" name="Body"  ROWS="10" COLS="60"></textarea><br>
</td>
</tr>
</table>
<input type=Submit value="发 表" name=Submit>&nbsp;<input type=reset name=Submit2 value="清 除" onClick="ClearReset()"></form>
<%end sub%>
<%sub addform2()%><center>
<form name="Dvform" method="post" action="?Action=add2" onSubmit="return check2();">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<th class="topbg" colspan="5">模板添加第二步--添加辅模板</th>
<tr>
<td colspan="4" align="center" class="tdbg">
<textarea id="Body" name="Body"  ROWS="10" COLS="60"></textarea><br>
</td>
</tr>
</table>
<input type=Submit value="发 表" name=Submit>&nbsp;<input type=reset name=Submit2 value="清 除" onClick="ClearReset()"></form>
<%end sub%>
<%sub changeform1()
  dim id,rs,strsql
  id=request.querystring("id")
  strsql="select * from Ex_Skin where id="&id
  set rs=Conn.execute(strsql)
%><center>
<form name="Dvform" method="post" action="?Action=change1&id=<%=id%>" onSubmit=";return check1();">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<th class="topbg" colspan="5">修改主模板</th>
<tr><td class="tdbg">模板名称：<font color="red">*</font></td><td class="tdbg"><input id="topic" name="topic" value="<%=rs("topic")%>"></td><td class="tdbg">作者：<font color="red">*</font></td><td class="tdbg"><input id="author" name="mbauthor" value="<%=rs("mbauthor")%>"></td></tr>
<tr><td colspan="4" class="tdbg" align="center">
<textarea name="Body" id="Body"><%=Server.HtmlEncode(rs("skin1")&" ")%></textarea><!--编辑器初始值的设置-->
<!--#include file="htmedit.asp"-->
</td></tr>
</table>
<input type=Submit value="发 表" name=Submit>&nbsp;<input type=reset name=Submit2 value="清 除" onClick="ClearReset()"></form>
<%end sub%>
<%sub changeform2()
 dim id,rs,strsql
  id=request.querystring("id")
  strsql="select * from Ex_Skin where id="&id
  set rs=Conn.execute(strsql)
%><center>
<form name="Dvform" method="post" action="?Action=change2&id=<%=id%>" onSubmit="return check2();">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<th class="topbg" colspan="5">修改辅模板</th>
<tr><td class="tdbg" colspan="4" align="center">
<textarea id="Body" name="Body"><%=Server.HtmlEncode(rs("skin2")&" ")%></textarea>
<!--#include file="htmedit.asp"-->
</td></tr>
</table>
<input type=Submit value="发 表" name=Submit>&nbsp;<input type=reset name=Submit2 value="清 除" onClick="ClearReset()"></form>
<%
end sub%>
   <br>
提示：以上选项必须填写！！<a href="http://www.ex123.net/bbs" target="_blank"><font color="red">如果您对添加模板有什么疑问,点此查看易心博客使用教程</font></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.ex123.net/skin" target="_blank"><font color="blue">点此下载更多精美模板</font></a>
</body>
</html>
