|
-
Jan 25th, 2012, 08:50 PM
#1
Thread Starter
Fanatic Member
Inserting at Position
This to me seems like it should be an almost simple solution, but for some reason, I'm having a brain fart.
I am building an extensive content management system for asp, complete with plugins and modules. The issue I'm running into is finding an efficient way of replacing the placeholder with the asp include.
Let me give you an example, in my past implementation, I had an extensive if... elseif... else statement that delimited the data with split command that would have to be hard coded into the index of the site.
My new solution is a little more elegant in theory, but I'm having issues implementing it.
The entire site is database driven, with records created for every page, there are tons of different modules scripted. These modules are held in another table on the database mapping out which include is needed for each different placeholder.
For example, I may have placeholders that look similar to
Code:
[$Calendar$]
[$Users$]
[$Blog Post$]
[$FacebookComments$]
etc
In the page table within the database, it may look similar to:
Code:
This is an example page created to showcase the power of the plugins. Below you'll find the gallery as well as a comment system.
[$Gallery$]
If you have any comments please post.
[$Comments$]
Thank you for your continued support
[$FacebookLike$]
As you can see from the example, I have 3 separate plugins in this single page, and my idea was something similar to:
Get position of placeholder
At placeholder position insert asp include
Continue page.
Repeat
Can anyone think of an elegant way of accomplishing this?
EDIT
Ok guys, I'm pretty sure I've managed to get this working. I don't wish to mark this resolved yet because I believe there may be a few bugs still. In case anyone was wondering, the method I chose was creating a custom method to run through the page, eliminate the placeholders, and in their place, use the execute command to execute functions that I had stored within the database. All the plugins have their own set of includes that are added to the index when they're installed.
This is fairly sloppy, so if anyone can think of some revisions for it I'd really appreciate it.
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
%>
Last edited by Mxjerrett; Jan 26th, 2012 at 01:16 AM.
If a post has been helpful please rate it. 
If your question has been answered, pull down the tread tools and mark it as resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|