<%
if (str_error_header = "Browser Error") Then
' Do Nothing
else
%>
<%
End If
%>
<%
if (bool_footer_error = false) Then
' if the error is happening while trying to print the footer, don't try to print the footer again
' or we'll just end up looping indefinately
PrintFooter()
End if
' exit the script after printing the error message
Response.End
End Sub
sub PrintFooter()
DisplayIncludes "pagefooter.html","Page Footer"
End sub
sub Pass()
if (request.form("ezy_password") <> "") OR (request.form("ezy_username") <> "") Then
PrintError "Login","Incorrect Login / Password combination Please try again", ""
End if
' print login stuff
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/login.inc")
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
fileContent = replace(fileContent,"$URL",URL)
fileContent = replace(fileContent,"$SCRIPTNAME",ScriptName)
response.write(fileContent)
else
PrintError "Template", "Cannot open Login Template: webedit_includes/login.inc", "File not Found"
End if
End Sub
sub PrintJSCommon()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/jscommon.inc")
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
' added for SSL
fileContent = replace(fileContent,"$HTTP",HTTPStr)
' End addition
fileContent = replace(fileContent,"$URL",URL)
fileContent = replace(fileContent,"$SCRIPTNAME",ScriptName)
fileContent = replace(fileContent,"$NEWDIR",NewDir)
fileContent = replace(fileContent,"$NEWIMAGEDIR",NewImageDirectory)
fileContent = replace(fileContent,"$CurrentImageDirectory",CurrentImageDirectory)
response.write(fileContent)
else
PrintError "Javascript Functions", "Cannot open Javascript Functions include file: webedit_includes/jscommon.inc", ""
End if
end sub
sub PrintDir()
' Print the contents of the directory
' First, load the javascript functions
if CurrentDirectory = "" then
CurrentDirectory = "/"
StartingDirectory = "/"
end if
PrintJSCommon()
Dim objFilename, objFSO, objFolder, objFiles, objSubfolders, i
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If (objFSO.FolderExists(server.mappath(CurrentDirectory))=true) Then
Set objFolder = objFSO.GetFolder(server.mappath(CurrentDirectory))
else
PrintError "Print Directory", "Cannot open directory for reading: " & CurrentDirectory, "Directory Not Found"
End if
Set objFiles = objFolder.Files
Set objSubfolders = objFolder.SubFolders
%>
<%
End sub
sub InsertLink()
' Print the contents of the directory
' First, load the javascript functions
if CurrentDirectory = "" then
CurrentDirectory = "/"
StartingDirectory = "/"
end if
PrintJSCommon()
Dim objFilename, objFSO, objFolder, objFiles, objSubfolders, i
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If (objFSO.FolderExists(server.mappath(CurrentDirectory))=true) Then
Set objFolder = objFSO.GetFolder(server.mappath(CurrentDirectory))
else
PrintError "Print Directory", "Cannot open directory for reading: " & CurrentDirectory, "Directory Not Found"
End if
Set objFiles = objFolder.Files
Set objSubfolders = objFolder.SubFolders
%>
<%
End sub
sub DeletePage()
' now go and actually delete the file/folder
' once again, assume the worst...
Dim str_file_to_delete
Dim isFolder, validFolder, validImage
validFolder = 0
validImage = 0
icon = "error.gif"
str_file_to_delete = request.querystring("filename")
isFolder = request.querystring("isFolder")
' Check to see if this is a valid filename and no invalid characters
if (bool_from_image_dir = "1") Then
validImage = "1"
End if
if (isFolder = "1") Then
validFolder = "1"
End if
ForceGoodInput str_file_to_delete,validFolder,validImage
if (str_file_to_delete = "") Then
' has the user let us know what file / folder they want to delete?
str_message = "Please select a file or folder to delete"
else
Dim toDelete
if (bool_from_image_dir = "1") Then
toDelete = Server.MapPath(CurrentImageDirectory & "\" & str_file_to_delete)
else
toDelete = Server.MapPath(CurrentDirectory & "\" & str_file_to_delete)
End if
Dim fso
if (isFolder = 1) Then
Set fso = CreateObject("Scripting.FileSystemObject")
if (fso.FolderExists(toDelete)) Then
fso.DeleteFolder(toDelete)
str_message = str_file_to_delete & " Deleted Successfully"
icon = "info.gif"
else
PrintError "Delete Directory", "Could not delete directory: "& CurrentDirectory & "/" & str_file_to_delete,"Directory not found"
End if
else
Set fso = CreateObject("Scripting.FileSystemObject")
if (fso.FileExists(toDelete)) Then
fso.DeleteFile(toDelete)
str_message = str_file_to_delete & " Deleted Successfully"
icon = "info.gif"
else
PrintError "Delete File", "Could not delete file: "& CurrentDirectory & "/" & str_file_to_delete,"File not found"
end if
End if
End if
PrintInfoMessage "Delete"
if (bool_from_image_dir) Then
' called from PrintImageDir?
%>
<%
else
%>
<%
End if
%>
<%
End sub
sub ShowRenamePage()
Dim str_file_to_rename, isFolder
str_file_to_rename = request.querystring("filename")
if (str_file_to_rename = "") Then
printError "Rename","Please select a file to rename.",""
End if
isFolder = request.querystring("isFolder")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/rename_page.inc")
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
fileContent = replace(fileContent,"$SCRIPTNAME",ScriptName)
fileContent = replace(fileContent,"$NEWDIR",NewDir)
fileContent = replace(fileContent,"$NEWIMAGEDIR",NewImageDirectory)
fileContent = replace(fileContent,"$isFolder",isFolder)
if (bool_from_image_dir = "1") Then
fileContent = replace(fileContent,"","")
End if
fileContent = replace(fileContent,"$str_file_to_rename",str_file_to_rename)
response.write(fileContent)
else
PrintError "Rename Template", "Cannot open Rename include file: webedit_includes/rename_page.inc", ""
End if
End Sub
sub RenameFile ()
' rename file/directory
' assume the worst
Dim success, str_file_to_rename, str_new_file_name, isFolder
success = 0
icon = "error.gif"
str_file_to_rename = request.form("FileName")
str_new_file_name = request.form("newfilename")
isFolder = request.form("isFolder")
if (str_new_file_name = "") Then
str_message = "Please enter a new name."
else
Dim validImage, validFolder
validImage = 0
validFolder = 0
if (bool_from_image_dir = "1") Then
validImage = 1
end if
if (isFolder = "1") Then
validFolder = 1
end if
ForceGoodInput str_file_to_rename,validFolder,validImage
ForceGoodInput str_new_file_name,validFolder,validImage
Dim fso, newFileName, oldFileName
if (bool_from_image_dir = "1") Then
oldFileName = Server.MapPath(CurrentImageDirectory & "\" & str_file_to_rename)
newFileName = Server.MapPath(CurrentImageDirectory & "\" & str_new_file_name)
else
oldFileName = Server.MapPath(CurrentDirectory & "\" & str_file_to_rename)
newFileName = Server.MapPath(CurrentDirectory & "\" & str_new_file_name)
End if
if (isFolder <> "1") Then
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(newFileName) OR fso.FolderExists(newFileName)) Then
str_message = "A file or folder with that name already exists."
else
fso.MoveFile oldFileName, newFileName
success = 1
str_message = str_file_to_rename & " renamed to " & str_new_file_name & " Successfully."
icon = "info.gif"
End if
Else
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(newFileName) OR fso.FileExists(newFileName)) Then
str_message = "A file or folder with that name already exists."
else
fso.MoveFolder oldFileName, newFileName
success = 1
str_message = str_file_to_rename & " renamed to " & str_new_file_name & " Successfully."
icon = "info.gif"
End if
End If
End if
PrintInfoMessage "Rename"
%>
<%
if (bool_from_image_dir <> "") Then
%>
<%
else
%>
<%
End if
if (success = 1) Then
%>
<%
else
%>
<%
End if
%>
<%
End Sub
sub ShowCopyPage()
Dim str_file_to_copy, isFolder
str_file_to_copy = request.querystring("filename")
if (str_file_to_copy = "") Then
printError "Copy","Please select a file to copy.",""
End if
isFolder = request.querystring("isFolder")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/copy_page.inc")
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
fileContent = replace(fileContent,"$SCRIPTNAME",ScriptName)
fileContent = replace(fileContent,"$NEWDIR",NewDir)
fileContent = replace(fileContent,"$NEWIMAGEDIR",NewImageDirectory)
fileContent = replace(fileContent,"$isFolder",isFolder)
if (bool_from_image_dir = "1") Then
fileContent = replace(fileContent,"","")
End if
fileContent = replace(fileContent,"$str_file_to_copy",str_file_to_copy)
response.write(fileContent)
else
PrintError "Copy Template", "Cannot open Copy include file: webedit_includes/copy_page.inc", ""
End if
End Sub
sub CopyFile ()
' rename file/directory
' assume the worst
Dim success, str_file_to_copy, str_new_file_name, isFolder
success = 0
icon = "error.gif"
str_file_to_copy = request.form("FileName")
str_new_file_name = request.form("newfilename")
isFolder = request.form("isFolder")
if (str_new_file_name = "") Then
str_message = "Please enter a file name."
else
Dim validImage, validFolder
validImage = 0
validFolder = 0
if (bool_from_image_dir = "1") Then
validImage = 1
end if
if (isFolder = "1") Then
validFolder = 1
end if
ForceGoodInput str_file_to_copy,validFolder,validImage
ForceGoodInput str_new_file_name,validFolder,validImage
Dim fso, newFileName, oldFileName
if (bool_from_image_dir = "1") Then
oldFileName = Server.MapPath(CurrentImageDirectory & "\" & str_file_to_copy)
newFileName = Server.MapPath(CurrentImageDirectory & "\" & str_new_file_name)
else
oldFileName = Server.MapPath(CurrentDirectory & "\" & str_file_to_copy)
newFileName = Server.MapPath(CurrentDirectory & "\" & str_new_file_name)
End if
if (isFolder <> "1") Then
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(newFileName) OR fso.FolderExists(newFileName)) Then
str_message = "A file or folder with that name already exists."
else
fso.CopyFile oldFileName, newFileName
success = 1
str_message = str_file_to_copy & " copied to " & str_new_file_name & " Successfully."
icon = "info.gif"
End if
Else
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(newFileName) OR fso.FileExists(newFileName)) Then
str_message = "A file or folder with that name already exists."
else
fso.CopyFolder oldFileName, newFileName
success = 1
str_message = str_file_to_copy & " copied to " & str_new_file_name & " Successfully."
icon = "info.gif"
End if
End If
End if
PrintInfoMessage "Copy"
%>
<%
if (bool_from_image_dir <> "") Then
%>
<%
else
%>
<%
End if
if (success = 1) Then
%>
<%
else
%>
<%
End if
%>
<%
End Sub
sub ShowCreateFolder ()
' print the Create Folder page...
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/create_folder.inc")
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
if (bool_from_image_dir = "1") Then
fileContent = replace(fileContent,"newdir","newimagedir")
fileContent = replace(fileContent,"$NEWDIR",newimagedirectory)
fileContent = replace(fileContent,"","")
else
fileContent = replace(fileContent,"$NEWDIR",NewDir)
End if
response.write(fileContent)
else
PrintError "Create Folder Template", "Cannot open Create Folder include file: webedit_includes/create_folder.inc", ""
End if
End Sub
sub CreateFolder ()
' now go and actually create the folder required..
' always assume the worst:
dim success, str_new_folder_name, newFolderName, fso, f
icon = "error.gif"
success = 0
str_new_folder_name = request.form("newfoldername")
if (str_new_folder_name = "") Then
' if we dont have the name for the new folder, ask the user
str_message = "Please enter a name for the new folder."
else
if (bool_from_image_dir = "1") Then
ForceGoodInput str_new_folder_name,1,1
newFolderName = Server.MapPath(CurrentImageDirectory & "\" & str_new_folder_name)
else
ForceGoodInput str_new_folder_name,1,0
newFolderName = Server.MapPath(CurrentDirectory & "\" & str_new_folder_name)
End if
set fso = server.CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(newFolderName) OR fso.FolderExists(newFolderName)) Then
' does a folder with that name already exist in the location?
str_message = "A file or folder with that name already exists."
else
' okay, we have all we need... now let us try to make the new folder
' or print an error message if we cannot
Set f = fso.CreateFolder(newFolderName)
'mkdir $str_new_folder_name, 0755 || &PrintError ("Create Folder", "Cannot create folder $str_new_folder_name \n", $!);
' now that all is good, keep going
str_message = "Directory " & str_new_folder_name & " Created Successfully."
success = 1
icon = "info.gif"
end if
End if
PrintInfoMessage "Create Folder"
if (bool_from_image_dir = "1") Then
%>
<%
else
%>
<%
End if
if (success = 1) Then
%>
<%
else
%>
<%
End if
%>
<%
End sub
sub ShowCreatePage()
%>
<%
End Sub
sub PrintTemplateDropdown()
Dim objFilename, objFSO, objFolder, objFiles, objSubfolders, i
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
if objFSO.FolderExists(server.mappath(TemplateDirectory)) Then
Set objFolder = objFSO.GetFolder(server.mappath(TemplateDirectory))
Set objFiles = objFolder.Files
For Each objFiles in objFolder.Files
For Each i in FileType
if (objFSO.GetExtensionName(objFiles.name) = i) Then
%>
<%
End if
next
next
else
PrintError "Template","Cannot open template directory: " & TemplateDirectory,""
End if
End Sub
sub CreateFile()
' create new file
' assume the worst
Dim success, str_new_file_name, str_template_file, newFileName, templateFileName, fso, f, ts, fileContent, re
success = 0
icon = "error.gif"
str_new_file_name = request.form("newfilename")
str_template_file = request.form("templateName")
if (str_new_file_name = "") Then
str_message = "Please enter a name for the new file"
else
if (str_template_file = "") Then
str_message = "Please choose a template from which to create your file"
end if
templateFileName = Server.MapPath(TemplateDirectory & "\" & str_template_file)
str_new_file_name = str_new_file_name & DefaultFileExtension
ForceGoodInput str_new_file_name,0,0
newFileName = Server.MapPath(CurrentDirectory & "\" & str_new_file_name)
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(newFileName) OR fso.FolderExists(newFileName)) Then
str_message = "A file or folder with that name already exists."
else
' Added for v5.0: images in templates
set f = fso.GetFile(templateFileName)
set ts = f.OpenAsTextStream(1, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
Set re = New RegExp
re.Pattern = "_template_files"
re.IgnoreCase = True
re.Global = True
' re.Multiline = True
fileContent = re.Replace(fileContent, TemplateDirectory & "/" & "_template_files")
set f = fso.OpenTextFile(newFileName, 2, true)
f.write(fileContent)
f.close
' End addition
str_message = str_new_file_name & " Created Successfully."
success = 1
icon = "info.gif"
End if
End if
PrintInfoMessage "Create New Page"
%>
<%
if (success = 1) Then
%>
<%
else
%>
<%
end if
%>
<%
End Sub
sub ShowUploadPage()
' print the upload file page
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/upload_page.inc")
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
fileContent = replace(fileContent, "$SCRIPTNAME", ScriptName)
fileContent = replace(fileContent, "$NEWDIR", newdir)
fileContent = replace(fileContent, "$NEWIMAGEDIR", newimagedirectory)
if (bool_from_image_dir = 1) Then
fileContent = replace(fileContent, "$$DONOTDELETE$$", "")
else
fileContent = replace(fileContent, "$$DONOTDELETE$$", "")
End if
response.write(fileContent)
else
PrintError "Template", "Cannot open Upload Page file: webedit_includes/upload_page.inc", "File not Found"
End if
End sub
sub UploadPage()
Response.Buffer = True
Dim success, toDofilesize, validImage
Dim ImageFileSize
ImageFileSize = Request.TotalBytes
if (bool_from_image_dir = "1") Then
toDofilesize = maximagesize
else
toDofilesize = maxfilesize
End if
if ((ImageFileSize > toDofilesize) OR (ImageFileSize < 630)) Then
str_message = "Please select a file to upload. (No Greater than " & maxfilesize & "bytes)"
icon = "error.gif"
else
' load object
Dim load
Set load = new Loader
' calling initialize method
load.initialize
' File name
Dim fileName
fileName = LCase(load.getFileName("sourcefile"))
' File binary data
Dim fileData
fileData = load.getFileData("sourcefile")
' File path
Dim filePath
filePath = load.getFilePath("sourcefile")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("sourcefile")
' File size
Dim fileSize
fileSize = load.getFileSize("sourcefile")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("sourcefile")
' Content Type
Dim contentType
contentType = load.getContentType("sourcefile")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "name"
Dim nameInput
' nameInput = load.getValue("name")
nameInput = filename
bool_from_image_dir = load.getValue("FromImageDir")
' Path where file will be uploaded
Dim pathToFile
if (CurrentDirectory = "") Then
CurrentDirectory = "/"
end if
if (CurrentImageDirectory = "") Then
CurrentImageDirectory = "/"
end if
if (bool_from_image_dir = "1") Then
ForceGoodInput fileName,0,1
pathToFile = Server.mapPath(CurrentImageDirectory) & "\" & fileName
else
ForceGoodInput fileName,0,0
pathToFile = Server.mapPath(CurrentDirectory) & "\" & fileName
end if
Dim fso
Dim msgExists
set fso = server.CreateObject("Scripting.FileSystemObject")
if (fso.FileExists(pathToFile)=true) OR (fso.FolderExists(pathToFile)=true)Then
msgExists = "Could not upload file. A file or folder with that name already exists"
else
' Uploading file data
Dim fileUploaded
fileUploaded = load.saveToFile ("sourcefile", pathToFile)
end if
' destroying load object
Set load = Nothing
If (fileUploaded = True) Then
icon = "info.gif"
str_message = fileName & " uploaded successfully."
success = 1
else
icon = "error.gif"
if msgExists = "" Then
str_message = fileName & " could not be uploaded."
else
str_message = msgExists
end if
success = 0
End If
End if
PrintInfoMessage "Upload File / Image"
If (bool_from_image_dir = "1") then
%>
<%
else
%>
<%
End if
If (success = 1) Then
%>
<%
else
%>
<%
End if
%>
<%
End Sub
sub EditPage()
Dim str_file_name, str_temp_file_name, tempFile
str_file_name = request.querystring("FileName")
' added for temp file
str_temp_file_name = "wep_temp_" & str_file_name
' end addition
if (str_file_name = "") then
PrintError "Edit File", "Please select a File to modify", ""
end if
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, includeFile
set fso = server.CreateObject("Scripting.FileSystemObject")
ForceGoodInput str_file_name,0,0
includeFile = Server.mapPath(CurrentDirectory & "/" & str_file_name)
' added for temp file
tempFile = Server.mapPath(CurrentDirectory & "/" & str_temp_file_name)
' End addition
if (fso.FileExists(includeFile)=false) Then
PrintError "Edit", "Cannot open file to edit:: " & CurrentDirectory & "/" & str_file_name, "File not Found"
' added for temp file
else
createTemp tempFile, includeFile
' end addition
End if
' Added for XHTML support
if OutputXHTML = "1" then
%>
<%
end if
' End addition
' Added to get path to script for Anchor and Hidden images
Dim pathToImages
pathToImages = left(scriptName, InStrRev(scriptName,"/")-1) & "/webedit_images"
' End addition
' Added for DW Templates and Forced Templates
Dim EditDefault
if ForceRestrictedEditing = "1" Then
EditDefault = 1
else
EditDefault = RestrictedEditing
End if
' End Addition
%>
<%
' Print toolbar
set fso = server.CreateObject("Scripting.FileSystemObject")
includeFile = Server.mapPath("webedit_includes/toolbar.inc")
filecontent = ""
if (fso.FileExists(includeFile)=true) Then
set f = fso.GetFile(includeFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
fileContent = replace(fileContent,"$STR_FILE_NAME",str_file_name)
fileContent = replace(fileContent,"$NEWDIR",newdir)
fileContent = replace(fileContent,"$URL",URL)
fileContent = replace(fileContent,"$SCRIPTNAME",ScriptName)
fileContent = replace(fileContent,"$STR_INC_FILE_EXT",FileTypeInclude)
' Added for Forced Restricted Editing / DW templates
fileContent = replace(fileContent,"$FORCE_RESTRICTED_EDITING",ForceRestrictedEditing)
fileContent = replace(fileContent,"$TEMPLATE_MODE",TemplateMode)
' End addition
response.write(fileContent)
else
PrintError "Template", "Cannot open Toolbar file:: webedit_includes/toolbar.inc", "File not Found"
End if
Randomize()
%>
<%
End sub
' Added for temp file
sub createTemp(newFile, originalFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
dim fso, f, ts, fileContent, re, re2
set fso = server.CreateObject("Scripting.FileSystemObject")
if (fso.FileExists(originalFile)=true) Then
set f = fso.GetFile(originalFile)
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
fileContent = fileContent & ts.ReadLine & vbCrLf
Loop
Set re = New RegExp
Set re2 = New RegExp
re.Pattern = "<\!--\s+#BeginEditable"
re2.Pattern = "<\!--\s+InstanceBeginEditable"
re.IgnoreCase = True
re2.IgnoreCase = True
re.Global = True
re2.Global = True
' re.Multiline = True
' re2.Multiline = True
If re.Test(fileContent) Then
ForceRestrictedEditing = "1"
' Old style DW templates
TemplateMode = "1"
fileContent = convertComments(fileContent)
elseif re2.Test(fileContent) Then
ForceRestrictedEditing = "1"
' New style DW MX templates
TemplateMode = "2"
fileContent = convertComments(fileContent)
End if
fileContent = convertScripts(fileContent)
set f = fso.OpenTextFile(newFile, ForWriting, true)
f.write(fileContent)
f.close
End if
End Sub
function convertComments(fileContent)
dim re, oMatches, intResult
' Convert HTML Comment Tags to Editable Divs
Set re = New RegExp
re.IgnoreCase = True
re.Global = True
' re.Multiline = True
' there seems to be no way to do what we need in a single replace,
' so lets extract BODY part (if present) first
re.Pattern = "]*>[\d\D]*<\/body>"
Set oMatches = re.Execute(fileContent)
if TemplateMode = "1" Then
re.Pattern = "<\!--\s+#BeginEditable\s+""(.+)""\s+-->([\s\S]*?)<\!--\s+#EndEditable\s+-->"
else
re.Pattern = "<\!--\s+InstanceBeginEditable\s+name=""(.+)""\s+-->([\s\S]*?)<\!--\s+InstanceEndEditable\s+-->"
End if
If oMatches.Count > 0 Then
intResult = re.Replace( oMatches.item(0).Value, "
")
End If
convertComments = fileContent
' End Conversion
End function
function revertComments(fileContent)
dim re
' Convert HTML Comment Tags to Editable Divs
Set re = New RegExp
re.Pattern = "
((?:(?:
]*>[\d\D]*?
)|[\d\D]+?)*?)
"
re.IgnoreCase = True
re.Global = True
' re.Multiline = True
if TemplateMode = "1" Then
fileContent = re.Replace(fileContent, "$2")
else
fileContent = re.Replace(fileContent, "$2")
End if
revertComments = fileContent
' End Conversion
End function
function convertScripts(fileContent)
dim re
Set re = New RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "<(script[^>]*?)language\s*?=\s*?(?!wep_no_script)([^>\s'""]+)([^>]*?)>"
fileContent = re.Replace( fileContent, "<$1language=""wep_no_script_$2""$3>" )
re.Pattern = "<(script[^>]*?)language\s*?=\s*?(['""])(?!wep_no_script)(\S+)\2([^>]*?)>"
fileContent = re.Replace( fileContent, "<$1language=""wep_no_script_$3""$4>" )
re.Pattern = "