Re: Inserting at Position
I'm fairly sure I've figured it out. After several hours of tinkering and research, I believed it's fool proof. At least I hope.
One request, if anyone can help me with a more efficient method of sorting my array, I'd be incredibly grateful.
Code:
<%
Function InsertPlugins(sData)
Dim strData: strData=sData
Dim lngUpper: lngUpper = 0
Dim strPosition()
Dim start
Dim strPlaceholder
Dim strPlugin
Dim i
[DATABASE CONNECTION STRING HERE]
Do Until rs2.EOF
start = 1
strPlaceholder = rs2.fields("pName")
Do Until start = 0
start = instr(start, strData, strPlaceholder)
If start> 0 then
Redim Preserve strPosition(10000,lngUpper)
strPosition(0, lngUpper) = start
strPosition(1, lngUpper) = strPlaceholder
start=start+len(strPlaceholder)
lngUpper = lngUpper + 1
End If
Loop
rs2.movenext
Loop
rs2.close
if int(lngUpper)>0 then
for ii=0 to lngupper - 1
temp1 = strPosition(0,ii)
temp2 = strPosition(1,ii)
strPosition(0,ii) = temp2
strPosition(1,ii) = temp1
next
strPosition2 = arraySort(strPosition, 1, "Number")
for ii=0 to lngupper - 1
temp1 = strPosition2(0,ii)
temp2 = strPosition2(1,ii)
strPosition2(0,ii) = temp2
strPosition2(1,ii) = temp1
next
response.write(left(strData,strPosition2(0,0)-1))
For i=0 to lngUpper - 1
if strPosition2(0, i) > 1 Then
If i<lngUpper - 1 Then
strPlugin = strPosition2(1,i)
rs2.open "SELECT * FROM tblPlugins WHERE pName='" & strPlugin & "'",conn
rs2.movefirst
execute(rs2.fields("pFunction"))
response.write(mid(strdata,strPosition2(0,i)+len(strPlugin), strPosition2(0,i+1)-strPosition2(0, i)-len(strPosition2(1, i))))
rs2.close
else
strPlugin = strPosition2(1,i)
rs2.open "SELECT * FROM tblPlugins WHERE pName='" & strPlugin & "'",conn
rs2.movefirst
execute(rs2.fields("pFunction"))
rs2.close
End if
else
strPlugin = strPosition2(1, i)
rs2.open "SELECT * FROM tblPlugins WHERE pName='" & strPosition2(1,i) & "'",conn
rs2.movefirst
execute(rs2.fields("pFunction"))
rs2.close
response.write(mid(strdata,strPosition2(0,i)+len(strPlugin), strPosition2(0,i+1)-strPosition2(0, i)-len(strPosition2(1, i))))
End If
Next
response.write(mid(strData, strPosition2(0, lngUpper - 1) + len(strPosition2(1,lngUpper - 1))))
end if
InsertPlugins = lngUpper
end Function
function arraySort(arToSort, sortBy, compareType)
Dim c, d, e, smallestValue, smallestIndex, tempValue
For c = 0 To uBound( arToSort, 2 ) - 1
smallestValue = arToSort( sortBy, c )
smallestIndex = c
For d = c + 1 To uBound( arToSort, 2 )
if compareType = "Text" then
if strComp( arToSort( sortBy, d ), smallestValue ) < 0 Then
smallestValue = arToSort( sortBy, d )
smallestIndex = d
End if
elseif compareType = "Date" then
if not isDate( smallestValue ) then
arraySort = arraySort( arToSort, sortBy, false)
exit function
else
if dateDiff( "d", arToSort( sortBy, d ), smallestValue ) > 0 Then
smallestValue = arToSort( sortBy, d )
smallestIndex = d
End if
end if
elseif compareType = "Number" then
if cint( arToSort( sortBy, d ) ) < cint(smallestValue) Then
smallestValue = arToSort( sortBy, d )
smallestIndex = d
End if
end if
Next
if smallestIndex <> c Then 'swap
For e = 0 To uBound( arToSort, 1 )
tempValue = arToSort( e, smallestIndex )
arToSort( e, smallestIndex ) = arToSort( e, c )
arToSort( e, c ) = tempValue
Next
End if
Next
arraySort = arToSort
end function
%>
Re: Inserting at Position
I haven't looked closely at the code but a quick glance appear that you know the name of your placeholder ahead of time and you're using that to find the position of where you want to do your insert. If that is the case couldn't you just use the Replace function instead of all the string manipulation?
Re: Inserting at Position
Quote:
Originally Posted by
MarkT
I haven't looked closely at the code but a quick glance appear that you know the name of your placeholder ahead of time and you're using that to find the position of where you want to do your insert. If that is the case couldn't you just use the Replace function instead of all the string manipulation?
Yes and no, replace would be able to remove the function, but it isn't going to find the location of where I have to insert the calls to the appropriate function.
Example
Code:
strData=replace(strData,Placeholder,FunctiontoExecute)
If I were to simply replace the placeholder with the Function, it would just write the function to the page, instead of executing it.
Re: Inserting at Position
Couldn't you call the function, place the return in a variable and use that in the replace call. I may not be seeing the bigger picture here.
Code:
Ret = FunctiontoExecute ' call the function
strData=replace(strData,Placeholder,Ret )
Re: Inserting at Position
MarkT, I actually just attempted what you said and it doesn't seem to worth. It throws a mismatch error.
The reason the example you showed doesn't work is some of these plugins' functions have extensive methods within them. Some of them writing to the form several times.
Re: Inserting at Position
Well, this is somewhat frustrating. After rethinking it with a well rested and clear mind. I think I may have managed to restructure the functions to be able to handle piping the information over to the Plugin Function.
Here is what it looks like now
Code:
Function InsertPlugins(sData)
[DATABASE QUERY]
strData=sData
do until rs2.eof
execute("funct =" & rs2.fields("pFunction"))
strData=replace(strData,rs2.fields("pName"),funct)
rs2.movenext
loop
if strData<>sData then
InsertPlugins2 = 1
response.write(strData)
end if
rs2.close
End Function
Originally the subroutines my other code called were writing to the form within their own function. This new way should work, but I'll keep the old code just incase.
Re: Inserting at Position
Just wondering why you use the replace() function instead of insert()? I only vaguely read through your code, still a little confused.
vb Code:
Dim str As String = "this is string value"
str = str.Insert(str.IndexOf("string"), "my ")
edit: Disregard my post... I didn't see this was for asp.net, I assumed some kind of vb script.
Re: Inserting at Position
Quote:
Originally Posted by
AceInfinity
Just wondering why you use the replace() function instead of insert()? I only vaguely read through your code, still a little confused.
vb Code:
Dim str As String = "this is string value"
str = str.Insert(str.IndexOf("string"), "my ")
edit: Disregard my post... I didn't see this was for asp.net, I assumed some kind of vb script.
Mine is asp, are you saying your code is asp.net?
Re: Inserting at Position
Quote:
Originally Posted by
Mxjerrett
Mine is asp, are you saying your code is asp.net?
No, and that's why I mentioned in my post to disregard my answer.
Quote:
Originally Posted by
AceInfinity
edit: Disregard my post... I didn't see this was for asp.net, I assumed some kind of vb script.
Re: Inserting at Position
Just curious why you want the code in a DB. Seems that would be a PITA to update the code. Why not just put the code Server Side Include files and then include them where you want?
Re: Inserting at Position
Quote:
Originally Posted by
Maverickz
Just curious why you want the code in a DB. Seems that would be a PITA to update the code. Why not just put the code Server Side Include files and then include them where you want?
I do have all the functions within includes, it's a module based system, when they want to execute the code they use the CMS and put something like [$ContactF$] then it reads the plugin table, when it finds the appropriate plugin, it executes the appropriate function found in the SSI
Re: Inserting at Position
Quote:
Originally Posted by
Mxjerrett
I do have all the functions within includes, it's a module based system, when they want to execute the code they use the CMS and put something like [$ContactF$] then it reads the plugin table, when it finds the appropriate plugin, it executes the appropriate function found in the SSI
To me the easiest thing would be to just have them use SSI format wherever they want the plugin to go:
<!--#include virtual="/includes/myFunction.inc" -->
However if you really want to use the [$ContactF$] format, it might make more sense to write an ISAPI filter to preprocess the document before IIS parses it. Have the ISAPI filter replace [$ContactF$] with <!--#include virtual="/includes/myFunction.inc" --> then have IIS parse it and the includes should work as normal.
So the flow would be as follows:
- Customer requests somepage.asp from IIS
- IIS sees that your ISAPI filter is to be used for .asp extentions and passes the request to the ISAPI filter
- The ISAPI filter retrieves the document requested and replaces the Text as needed.
- The ISAPI filter returns the document to IIS for processing.
- IIS executes the code in the includes as normal and returns the HTML to the customer.
Re: Inserting at Position
Quote:
Originally Posted by
Maverickz
To me the easiest thing would be to just have them use SSI format wherever they want the plugin to go:
<!--#include virtual="/includes/myFunction.inc" -->
However if you really want to use the [$ContactF$] format, it might make more sense to write an ISAPI filter to preprocess the document before IIS parses it. Have the ISAPI filter replace [$ContactF$] with <!--#include virtual="/includes/myFunction.inc" --> then have IIS parse it and the includes should work as normal.
So the flow would be as follows:
- Customer requests somepage.asp from IIS
- IIS sees that your ISAPI filter is to be used for .asp extentions and passes the request to the ISAPI filter
- The ISAPI filter retrieves the document requested and replaces the Text as needed.
- The ISAPI filter returns the document to IIS for processing.
- IIS executes the code in the includes as normal and returns the HTML to the customer.
I wouldn't know of a decent way of deploying this in mass. This is a deployable CMS system that allows for quick installation on someone's server. I'm not sure how I could make it modify ISAPI filters directly.
Re: Inserting at Position
If you use an installer to deploy, it should be able to configure this. If you just want to unzip and go then yeah not so easy.
Re: Inserting at Position
Quote:
Originally Posted by
Maverickz
If you use an installer to deploy, it should be able to configure this. If you just want to unzip and go then yeah not so easy.
Yeah, you just move the files to the server and run the initialing page.