<!--#include file="fy.Template.asp" -->
<!--#include file="../api.asp" -->
<%
Class ACT_Code
	
	
	Dim Reg
 	public Nodes
	Private Domain,ASys
	Private Sub Class_Initialize()
		Domain = fycms.ACTURL
		ASys = fycms.ActSys
		Set Reg = New RegExp
		Reg.Ignorecase = True
		Reg.Global = True
		End Sub
        Private Sub Class_Terminate()
		End Sub
		Public Function LabelReplaceAll(TemplateContent)
 		  Dim tpl
		Set Tpl = New Cls_Template
		LabelReplaceAll=Tpl.Load(TemplateContent)
	   End Function

		Function GetNodeText(NodeName)
		 Dim N
		 If IsObject(Nodes) Then
		  set N=nodes.SelectSingleNode("@" & NodeName)
		  If Not N is Nothing Then GetNodeText=N.text
		 End If
		End Function
 
 	Public Function ArticleContent(ModeID,R_RS)
 		'on error resume next
 		Dim TempletContent,ArticleContents,ArticleContentArr,TotalPage,I,CurrPage,ArticlePageStr,FileName
		Dim fext,n,FilePathName,StrContent,ContentText,FilePath
		Application(fycmsN & "classid")=GetNodeText("classid")
		Application(fycmsN & "fycms_TCJ_Type")="ARTICLECONTENT"
		Application(fycmsN & "modeid")=ModeID
		Application(fycmsN & "id")=GetNodeText("id")
 
		StrContent = LoadTemplate(GetNodeText("templateurl"))'读取模板路径
 		'StrContent = LabelReplaceAll(TempletContent)'标签转换


		If fycms.ACT_C(modeid,18)="1" Then
			 ArticleContents=getcontentxml(modeid,GetNodeText("id"),GetNodeText("addtime"))
		Else 
 			ArticleContents = GetNodeText("content") 
		End If 
		If ArticleContents="" Then ArticleContents = ""
		Dim FileNameUrl
		FilePath=ASys&fycms.ACT_C(ModeID,6)&GetNodeText("filename")
 		If fycms.ACT_L(fycms.GetParent(GetNodeText("classid")),13)="1" Then 
			FilePath = asys &fycms.ACT_L(fycms.GetParent(GetNodeText("classid")),14)&"/"&GetNodeText("filename") 
			FileNameUrl=asys &GetNodeText("filename") 
		Else 
			FilePath = asys & fycms.ACT_C(ModeID,6)& GetNodeText("filename")
			FileNameUrl= FilePath
		End If 
 
  		If Right(fycms.ACT_L(GetNodeText("classid"),16),1)<>"/" Then 
			 FilePathName= FilePath&fycms.ACT_C(ModeID,11)'文件路径加扩展名,下,截取/字符.以便生成相应文件夹
			 FilePath=Replace(FilePathName, MID(FilePathName, InStrRev(FilePathName, "/")), "")
		 Else
		 	 FilePathName= FilePath&"/Index"&fycms.ACT_C(ModeID,11)
		End If 
		If InStr(ArticleContents, "[NextPage]") > 0 Then 
			FExt = MID(Trim(FilePathName), InStrRev(Trim(FilePathName), "."))
			FileName = Replace(Trim(FilePathName), FExt, "")
		End If 
	
 			 Call fycms.CreateFolder(FilePath)
			 If InStr(ArticleContents, "[NextPage]") > 0 Then 
					ArticleContentArr = Split(ArticleContents, "[NextPage]")
					TotalPage = UBound(ArticleContentArr) + 1
					 For I = 0 To UBound(ArticleContentArr)
					   CurrPage = I + 1
					   If TotalPage > 1 Then
							   If I = 0 Then
								 ArticlePageStr = "<p><div align=center><a href=" &  FileNameUrl & "_" & (CurrPage + 1) & FExt & ">下一页</a><br>"
							   ElseIf I = 1 And I <> TotalPage - 1 Then
								 ArticlePageStr = "<p><div align=center><a href=" &  FileNameUrl&fycms.ACT_C(ModeID,11) & ">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=" &  FileNameUrl & "_" & (CurrPage + 1) & FExt & ">下一页</a><br>"
							   ElseIf I = 1 And I = TotalPage - 1 Then
								 ArticlePageStr = "<p><div align=center><a href=" &  FilePathName & ">上一页</a><br>"
							   ElseIf I = TotalPage - 1 Then
								 ArticlePageStr = "<p><div align=center><a href=" &  FileNameUrl & "_" & (CurrPage - 1) & FExt & ">上一页</a><br>"
							   Else
								ArticlePageStr = "<p><div align=center><a href=" &  FileNameUrl & "_" & (CurrPage - 1) & FExt & ">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=" &  FileNameUrl & "_" & (CurrPage + 1) & FExt & ">下一页</a><br>"
							   End If
							   ArticlePageStr = ArticlePageStr & "本文共<font color=red> " & TotalPage & " </font>页,第&nbsp;&nbsp;"
						   For N = 1 To TotalPage
							  If N = 1 Then
								 If CurrPage = N Then
								  ArticlePageStr = ArticlePageStr & "<font color=red>[" & N & "]</font>&nbsp;&nbsp;"
								 Else
								  ArticlePageStr = ArticlePageStr & "<a href=" &  FileNameUrl&fycms.ACT_C(ModeID,11) & ">[" & N & "]</a>&nbsp;&nbsp;"
								 End If
							   Else
								 If CurrPage = N Then
								   ArticlePageStr = ArticlePageStr & "<font color=red>[" & N & "]</font>&nbsp;&nbsp;"
								 Else
								   ArticlePageStr = ArticlePageStr & "<a href=" &  FileNameUrl & "_" & N & FExt & ">[" & N & "]</a>&nbsp;&nbsp;"
								End If
							  End If
							  
							  If TotalPage > 10 Then
							   If N Mod 10 = 0 Then ArticlePageStr = ArticlePageStr & "<br>"
							  End If
							Next
							ArticlePageStr = ArticlePageStr & "页</div></p>"
						 Else
						  ArticlePageStr = ""
						 End If
					If CurrPage <> 1 Then FilePathName =  FileName & "_" & CurrPage & FExt
					ContentText=StrContent
					TempletContent = ReplaceArticleContent(GetNodeText("id"),ModeID,ContentText,ArticleContentArr(I) & ArticlePageStr)
					Call SaveFile(ContentText,FilePathName)
					Next
				Else
					Call SaveFile(ReplaceArticleContent(GetNodeText("id"),ModeID,StrContent,ArticleContents),FilePathName)
				End If 
		End Function

		Function ReplaceArticleContent(ID,ModeID,TempletContent,ArticleContents)
 			Dim rs
			Set rs=fycms.actexe("select * from  "&fycms.ACT_C(ModeID,2)&" where id="&ID)
			If Not rs.eof Then 
 				 Dim newt:Set newt=New Cls_Template
 				 TempletContent=newt.GetContent(ModeID,rs,TempletContent,ArticleContents)'自定义函数
			End If 
			ReplaceArticleContent=TempletContent
 		End Function
 
  

		Function CreateArticleList(ModeID,FolderRs)
			Dim TemplateContent,IndexHtml,FolderDir
			Dim FilePath
			Application(fycmsN & "fycms_TCJ_Type")="Folder"
			Application(fycmsN & "modeid")=FolderRs("modeid")
			Application(fycmsN & "classid")=FolderRs("classid")
 			IndexHtml = FolderRs("Extension")
			If Trim(IndexHtml)="" Then IndexHtml="index.html"
 		 	If Trim(FolderRs("actlink"))="3" Then 
				TemplateContent= LoadTemplate(FolderRs("FolderTemplate"))
 				'TemplateContent = LabelReplaceAll(TemplateContent)
				TemplateContent=InStrRep(TemplateContent, "{info:content}", FolderRs("content"))
 
				 If InStr(TemplateContent, "{info:title}") > 0  Then
					If Trim(fycms.ACT_L(Application(fycmsN & "classid"),25))<>"" Then 
						 TemplateContent = rep(TemplateContent, "{info:title}",fycms.ACT_L(Application(fycmsN & "classid"),25))
					Else 
						 TemplateContent = rep(TemplateContent, "{info:title}",fycms.ACT_L(Application(fycmsN & "classid"),2))
					End If 
				 End If


				

				If Trim(FolderRs("makehtmlname"))<>"" Then 
					TemplateContent = LabelReplaceAll(TemplateContent)
     				  Call SaveFile(TemplateContent,fycms.GetPath(FolderRs("classid"),FolderRs("makehtmlname")))
				End If 
			Else 
 				FilePath=fycms.getclasspath(FolderRs("classid"))
  				Call fycms.CreateFolder(FilePath)
 				Dim newt:Set newt=New Cls_Template
				Dim CurrPage
 				TemplateContent=newt.GetTabContentPage(LoadTemplate(FolderRs("FolderTemplate")),FolderRs("classid"),CurrPage,FilePath,IndexHtml,true,"")'自定义函数
 			 End If

 		End Function
  


End Class
%>