<!--#include file="Inc/Config.asp" -->
<%
Server.ScriptTimeOut=99999999
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SQL版CIXIBLOG2.0 TO CITYBLOG1.0升级程序
'程序作者:陈若帆 Oicq:26092554
'升级前请先做好备份
'升级前请先查看升级帮助,做好升级准备
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim UserRs,Article_ByMonth,StrIngs,UserID
Dim RegExpObj,BodyText,ARTID,LinkRs,TBUser_Name 
Dim TBBlog_Name,BlogTopTitle,PhotoToARs,SqlString
DIM User8,User1,User2,User9,User3,User7


Sub SaveXml(XmlString,XmlPhat,UserID)
	Dim XmlDoc
	Set XmlDoc = Server.CreateObject("Msxml2.DOMDocument")
	xmlDoc.loadXML (XmlString)
	xmlDoc.Save (Server.MapPath(CblogObj.GetDir(UserID) & "/" &XmlPhat))
	Set xmlDoc = Nothing
End Sub

Sub UpdateAB()
	Conn.Execute("update Article Set Isphoto=0 Where Isphoto Is Null")
	Conn.Execute("Update Tb_User Set User_Sex='男' Where User_Sex='' Or User_Sex='M'")
	Conn.Execute("Update Tb_User Set User_Sex='女' Where User_Sex='F'")
	Conn.Execute("Update Tb_User Set Blog_Title='我写,我读,我博客...' Where Blog_Title=''")
	Conn.Execute("Update Article Set Whather='晴' Where Whather='1'")
	Conn.Execute("Update Article Set Whather='雪' Where Whather='0'")
	Conn.Execute("Update Article Set Whather='雪' Where Whather='5'")
	Conn.Execute("Update Article Set Whather='多云' Where Whather='2'")
	Conn.Execute("Update Article Set Whather='雨' Where Whather='7'")
	Conn.Execute("Update Article Set Whather='雨' Where Whather='3'")
	Conn.Execute("Update Article Set Whather='多云转晴' Where Whather='6'")
	Conn.Execute("Update Article Set Whather='台风' Where Whather='4'")
	Conn.Execute("Update Tb_User_Class Set photo=0")
End Sub
Sub UPPHOTOCLASS()'复制相册分类到文章分类表
	Set PhotoToARs=Conn.ExeCute("Select User_ID,PhotoClass From Tb_Photo_Class Order By ID")
	Do While Not PhotoToARs.Eof
		Conn.Execute("INSERT INTO [Tb_User_Class](User_id,Blog_Class,Photo) VALUES("& PhotoToARs(0) &",'"& PhotoToARs(1) &"',1)")
	PhotoToARs.MoveNext
	Loop
	PhotoToARs.Close:Set PhotoToARs=Nothing
End Sub
Sub PhotoToArticle()'复制相册到文章表
	Conn.ExeCute("Update Article Set Article_ByClass='0000000默认分类' Where Article_ByClass='Default' Or Article_ByClass='默认分类'")
	Set PhotoToARs=Conn.ExeCute("Select PhotoID,User_ID,Photo_Class,Photo,PhotoTitle,PhotoInfo,PhotoTop,PhotoDate,SeeCount,ReCount,(SELECT User_Name From Tb_User Where ID=Tb_Photo.User_id) From Tb_Photo Order By PhotoID")
	Do While Not PhotoToARs.Eof
			SqlString="INSERT INTO [Article] (User_ID,User_Name,Article_Title,Article_Zy,Blog_Info,Whather,Article_ByMonth,Article_Hid,Article_Time,Article_ByClass,Article_Code,Article_Form,Article_Tag,Photo,IsPhoto,See_Count,Re_Count)"
			SqlString=SqlString & " VALUES("& PhotoToARs(1) &",'"& PhotoToARs(10) &"','"& PhotoToARs(4) &"','"& PhotoToARs(5) &"','"& PhotoToARs(5) &"','未知天气','无',0,'"&  PhotoToARs(7)  &"','"& PhotoToARs(2) &"','108','未知','摄影|图片|相册|照片','"& PhotoToARs(3)  &"',1,"&PhotoToARs(8)&","&PhotoToARs(9)&")"
            On Error resume next
			Conn.ExeCute(SqlString)
			ARTID=CONN.EXECUTE("SELECT Top 1 Article_ID FROM [Article] Order By Article_ID Desc")(0)
			Conn.ExeCute("Update Tb_Reply Set Reply_Blog_ID="& ARTID &" Where Reply_Blog_ID="& PhotoToARs(0) &"")
	PhotoToARs.MoveNext
	Loop
	PhotoToARs.Close:Set PhotoToARs=Nothing
End Sub
Sub UpdateByMonth()'更改日期
	Set RS=Conn.ExEcUTE("Select Article_ID,Article_Time From Article Order By Article_ID")
	Do While Not Rs.Eof
		Article_ByMonth=Year(Rs(1))&month(Rs(1))&"||"&Year(Rs(1))&"年"&MonthName(Month(Rs(1)))&"份"
		Conn.ExeCute("Update Article Set Article_ByMonth='"& Article_ByMonth &"' Where Article_ID="& Rs(0) &"")
	Rs.MoveNext
	Loop
	Rs.Close:Set Rs=Nothing
End Sub
Sub UpdateClass()'升级分类
	Conn.ExeCute("Update Article Set Article_ByClass='1111111默认相册' Where Article_ByClass='Default' Or Article_ByClass='默认分类' Or Article_ByClass='默认相册'")
	Set RS=Conn.ExEcUTE("Select id,User_id,Blog_Class From Tb_User_Class")
	Do While Not Rs.Eof
		Article_ByMonth="0000000" & Rs(0)
		Article_ByMonth=Right(Article_ByMonth,7) & Rs(2)
		Conn.ExeCute("Update Article Set Article_ByClass='"& Article_ByMonth &"' Where Article_ByClass='"& Rs(2) &"'")
	Rs.MoveNext
	Loop
	Rs.Close:Set Rs=Nothing
End Sub

Sub SaveUserLinkXml(UserID,Str)
	Dim XmlString,XmlRs,iii,Arr
	xmlString = "<?xml version=""1.0""  encoding=""gb2312""?>"
	xmlString = xmlString & "<xml><index>"
	IF Str="" Then
			xmlString = xmlString & "<blog>"
			xmlString = xmlString & "<classname><![CDATA[没有联接]]></classname>"
			xmlString = xmlString & "</blog>"
	Else
		Str=Mid(Str,3)
		Arr=Split(Str,"||")
		For iii = 0 To UBound(Arr)
			xmlString = xmlString & "<blog>"
			xmlString = xmlString & "<classname><![CDATA["&Arr(iii)&"]]></classname>"
			xmlString = xmlString & "</blog>"
		Next
	End IF
	xmlString = xmlString & "</index></xml>"
	SaveXml XmlString,"Link.xml",UserID
End Sub

Call UpdateAB()
Response.Write "第1步完成<br/>"
Response.End
Call UPPHOTOCLASS()
Response.Write "第2步完成<br/>"
Call PhotoToArticle()
Response.Write "第3步完成<br/>"
Call UpdateByMonth()
Response.Write "第4步完成<br/>"
Call UpdateClass()
Response.Write "第5步完成<br/>"

Set UserRs=Conn.Execute("Select ID,User_Name,User_Sex,User_Mail,Blog_Url,Blog_Name,Blog_Title,Blog_Info,User_Photo,User_Date From Tb_User Order By ID")
Do While Not UserRs.Eof
	'复制相关文件
	CBlogObj.Copyfile CityBlogDir & "Template/default/", CBlogObj.GetDir(UserRs(0))
	'End复制相关文件
	'生成SETUP.ASP
	BlogTopTitle=UserRs(6)
	IF IsDom Then 
		BlogTopTitle=BlogTopTitle & " http://" & UserRs(4) & "." & WebHost
	End IF
	UserID=UserRs(0)
	User8=UserRs(8)
	User1=UserRs(1)
	User2=UserRs(2)
	User9=UserRs(9)
	User3=UserRs(3)
	User7=UserRs(7)
	TBBlog_Name=UserRs(5) & "(" & User1 & "'S Blog)"
	BodyText=CBlogObj.GetTxt(CityBlogDir & "inc/usersetup.inc")
	Set RegExpObj=new RegExp
	RegExpObj.IgnoreCase =true
	RegExpObj.Global=True
	RegExpObj.Pattern="(#UserID#)"
	BodyText=RegExpObj.Replace(BodyText,UserID)
	RegExpObj.Pattern="(#UserBlogTitle#)"
	BodyText=RegExpObj.Replace(BodyText,BlogTopTitle)
	RegExpObj.Pattern="(#BlogName#)"
	BodyText=RegExpObj.Replace(BodyText,TBBlog_Name)
	RegExpObj.Pattern="(#PageSize#)"
	BodyText=RegExpObj.Replace(BodyText,10)
	RegExpObj.Pattern="(#photo#)"
	BodyText=RegExpObj.Replace(BodyText,User8)
	RegExpObj.Pattern="(#UserName#)"
	BodyText=RegExpObj.Replace(BodyText,User1)
	RegExpObj.Pattern="(#Sex#)"
	BodyText=RegExpObj.Replace(BodyText,User2)
	RegExpObj.Pattern="(#Date#)"
	BodyText=RegExpObj.Replace(BodyText,User9)
	RegExpObj.Pattern="(#Email#)"
	BodyText=RegExpObj.Replace(BodyText,User3)
	RegExpObj.Pattern="(#City#)"
	BodyText=RegExpObj.Replace(BodyText,"没有填写")
	RegExpObj.Pattern="(#Announcement#)"
	BodyText=RegExpObj.Replace(BodyText,User7)
	Set RegExpObj=nothing
	CBlogObj.WriteStream CBlogObj.GetDir(UserID) & "/setup.asp",BodyText
	'END生成SETUP.ASP
	
	
	'生成友情联接
	StrIngs=""
	Set LinkRs=Conn.Execute("Select LinkName,LinkUrl From Tb_Link Where User_ID="& UserID &"")
	Do While Not LinkRs.Eof
		StrIngs=StrIngs & "||<a href="""& LinkRs(1) &""">"& LinkRs(0) &"</a>"
	LinkRs.MoveNext
	Loop
	LinkRs.Close:Set LinkRs=Nothing
	Call SaveUserLinkXml(UserRs(0),StrIngs)
	'End 生成友情联接
	CblogObj.SaveUserClassXml(UserRs(0))
	CblogObj.SaveUserMonthXml(UserRs(0))
	CblogObj.SaveReXml(UserRs(0))
UserRs.MoveNext
Loop
UserRs.Close:Set UserRs=Nothing
Response.Write "完成升级了,请删除此文件<br/>"
Set CblogObj=NotHing
Response.End
%>