/    Sign up×
Community /Pin to ProfileBookmark

asp templates to php templates

i have an asp website using templates. Now I have changed from windows to linux and need to convert the website. If i understand it right I need to change the tenplateobj to a php class. I am hoping to find an example website or cms that uses the same type system as I am using so I can compare them. Not sure how much info I need to post to make it clear.

[code]

Usage:
LoadTemplate server.mappath(“/templates/new.html”), “main”
SetVar “ID”, 2
SetVar “Value”, “Name”
Parse “DynBlock”, False ‘or True if you want to create a list
Parse “main”, False
PrintVar “main”
[/code]

this is basically the way it is used and here is the code.

[code]

Dim objFSO

Dim DBlocks
Dim ParsedBlocks

Sub SetBlock(sTplName, sBlockName)
Dim nName
if not DBlocks.Exists(sBlockName) then
DBlocks.Add sBlockName, getBlock(DBlocks(sTplName), sBlockName)
end if
DBlocks(sTplName) = replaceBlock(DBlocks(sTplName), sBlockName)

nName = NextDBlockName(sBlockName)
while not (nName = “”)
SetBlock sBlockName, nName
nName = NextDBlockName(sBlockName)
wend
End Sub

Sub LoadTemplate(sPath, sName)
Dim nName
if not isObject(objFSO) then
Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)
Set DBlocks = Server.CreateObject(“Scripting.Dictionary”)
Set ParsedBlocks = Server.CreateObject(“Scripting.Dictionary”)
end if
if objFSO.FileExists(sPath) then
DBlocks.Add sName, objFSO.OpenTextFile(sPath).ReadAll
nName = NextDBlockName(sName)
while not (nName = “”)
SetBlock sName, nName
nName = NextDBlockName(sName)
wend
end if
End Sub

Sub UnloadTemplate()
if isObject(objFSO) then
Set objFSO = nothing
Set DBlocks = nothing
Set ParsedBlocks = nothing
end if
End Sub

Function GetVar(sName)
GetVar = DBlocks(sName)
End Function

Function SetVar(sName, sValue)
if ParsedBlocks.Exists(sName) then
ParsedBlocks(sName) = replace(replace(sValue, “{“, “{”), “}”, “}”)
else
ParsedBlocks.add sName, replace(replace(sValue, “{“, “{”), “}”, “}”)
end if
End Function

Function Parse(sTplName, bRepeat)
if ParsedBlocks.Exists(sTplName) then
if bRepeat then
ParsedBlocks(sTplName) = ParsedBlocks(sTplName) & ProceedTpl(DBlocks(sTplName))
else
ParsedBlocks(sTplName) = ProceedTpl(DBlocks(sTplName))
end if
else
ParsedBlocks.add sTplName, ProceedTpl(DBlocks(sTplName))
end if
End Function

Function PrintVar(sName)
PrintVar = ParsedBlocks(sName)
End function

Function ProceedTpl(sTpl)
Dim regEx, sMatch, oMatches, sName, sTTpl

sTTpl = sTpl
sMatch = getNextPattern(sTTpl, 1)
while len(sMatch) > 0
sName = mid(sMatch, 2, len(sMatch) – 2)
if ParsedBlocks.Exists(sName) then
sTTpl = replace(sTTpl, sMatch, ParsedBlocks(sName))
else
sTTpl = replace(sTTpl, sMatch, DBlocks(sName))
end if
sMatch = getNextPattern(sTTpl, 1)
wend
ProceedTpl = sTTpl
End Function

Function getNextPattern(str, begin)
Dim res, b, e, isOk
Dim w(5)

b = instr(begin, str, “{“)
if b > 0 then
e = instr(b, str, “}”)
w(1) = instr(b, str, ” “)
w(2) = instr(b, str, “;”)
w(3) = instr(b, str, “:”)
w(4) = instr(b, str, “=”)
w(5) = instr(b, str, “(“)
isOk = true
For i = 1 to 5
if w(i) < e and w(i) > b then isOk = false
Next
if isOk then
res = mid(str, b, e – b + 1)
else
res = getNextPattern(str, e)
end if
else
res = “”
end if
getNextPattern = res
End Function

Function getBlock(sTemplate, sName)
Dim BBloc, EBlock, alpha

alpha = len(sName) + 12
BBlock = instr(sTemplate, “<!–Begin” & sName & “–>”)
EBlock = instr(sTemplate, “<!–End” & sName & “–>”)
if not (BBlock = 0 or EBlock = 0) then
getBlock = mid(sTemplate, BBlock + alpha, EBlock – BBlock – alpha)
else
getBlock = “”
end if
End Function

Function replaceBlock(sTemplate, sName)
Dim BBloc, EBlock

BBlock = instr(sTemplate, “<!–Begin” & sName & “–>”)
EBlock = instr(sTemplate, “<!–End” & sName & “–>”)
if not (BBlock = 0 or EBlock = 0) then
replaceBlock = left(sTemplate, BBlock – 1) & “{” & sName & “}” & right(sTemplate, len(sTemplate) – EBlock – len(“<!–End” & sName & “–>”) + 1)
else
replaceBlock = sTemplate
end if
end function

Function NextDBlockName(sTemplateName)
dim BTag, ETag, sName, sTemplate
sTemplate = DBlocks(sTemplateName)

BTag = instr(sTemplate, “<!–Begin”)
if BTag > 0 then
ETag = instr(BTag, sTemplate, “–>”)
sName = Mid(sTemplate, BTag + 9, ETag – (BTag + 9))
if instr(sTemplate, “<!–End” & sName & “–>”) > 0 then
NextDBlockName = sName
else
NextDBlockName = “”
end if
else
NextDBlockName = “”
end if
End function

‘Print all Dynamic Variables
Function PrintAll()
dim aPBlocks
dim aDBlocks
dim i, res

aPBlocks = ParsedBlocks.Items
aDBlocks = DBlocks.Items
res = “<table border=1>”
for i = 1 to UBound(aDBlocks)
res = res & “<tr><td><pre>” & ToHTML(aDBlocks(i)) & “</pre></td></tr>”
next
for i = 1 to UBound(aPBlocks)
res = res & “<tr><td><pre>” & ToHTML(aPBlocks(i)) & “</pre></td></tr>”
next
res = res & “</table>”
PrintAll = res
End Function
[/code]

does that look like any php system out there. I would really like to use the same html and css files. I just need to learn how to convert the asp code.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @dvdljns spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...