Author |
Topic |
|
Jorrit787
Average Member
Netherlands
681 Posts |
Posted - 13 December 2004 : 04:16:27
|
Not entirely sure if this belongs here, but if not then you can move it
I would like to know if it is possible to create tags, for example [hidden] and [/hidden], that work like this:
Normal users can't use the feature, but when admins or moderators use it, the text in-between the tags will only appear to admins and moderators I think it would be useful for admins and mods to leave little notes to each other to explain why they edit a specific post etc. that display directly under the post. |
eXtremeGossip |
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 13 December 2004 : 04:51:17
|
You could do it with the ExtraTags function in inc_func_common.asp, I guess.if mlev > 2 then
'process the [hidden][/hidden] tags
else
'replace everything inbetween the [hidden][/hidden] tags and the tags themselves by something like this :
'<b>Hidden for normal users</b>
end if Something like that. However, I have no clue on how to do the second one... |
portfolio - linkshrinker - oxle - twitter |
Edited by - MarcelG on 13 December 2004 04:52:38 |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 13 December 2004 : 10:36:20
|
I have a function I could probably create for you but the syntax would look like this:
[hidden=This guy does not know what he's talking about, what should we do with him?]
Thanks to -gary and his approach with regular expressions, it would be pretty easy. |
|
|
|
Jorrit787
Average Member
Netherlands
681 Posts |
Posted - 13 December 2004 : 11:39:47
|
That sounds great |
eXtremeGossip |
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 13 December 2004 : 15:09:11
|
Dayve, you reckon it cannot be done (easily) with the [hidden]Hide this text[/hidden] method ? |
portfolio - linkshrinker - oxle - twitter |
|
|
-gary
Development Team Member
406 Posts |
Posted - 13 December 2004 : 17:41:33
|
A RegEx is really the way to go here. This will give you one shotgun delete of everything between and including the tags. The pure VB way would require a bit more code and multiple passes for each iteration.
RegEx
<%
txt = HideText(txt)
function HideText(txt)
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
Set regEx = New RegExp
regEx.Pattern = "\[hidden.*\/hidden\]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(txt)
HideText = regEx.Replace(txt, "")
end function
%>
VBScript
<%
for each match in whatever
txt = Replace(txt, "[hidden]" & TagData("hidden", txt) & "[/hidden]", "")
next
function TagData(strTag, strSource)
lngStart = InStr( 1, LCase( strSource ), Chr(91) & LCase( strTag ) )
If lngStart > 0 Then
lngStart = InStr( lngStart, LCase( strSource ), Chr(93) ) + 1
lngStop = InStr( lngStart, LCase( strSource ), Chr(91) & Chr(47) & LCase( strTag ) & Chr(93) )
If lngStart > 0 And lngStop > lngStart Then
strData = Trim( Mid( strSource, lngStart, lngStop - lngStart ) )
end if
End If
TagData = strData
end function
%>
|
KawiForums.com
|
Edited by - -gary on 13 December 2004 17:45:07 |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 13 December 2004 : 20:13:16
|
LOL, there ya go... -gary has really opened my eyes to a lot of possibilities using regex lately. |
|
|
|
Jorrit787
Average Member
Netherlands
681 Posts |
Posted - 14 December 2004 : 11:52:25
|
To what file should I add this text? And should I use the RegEx or VBScript version?
This will allow moderators and admins to use the [hidden] [/hidden] tags to add text to posts that only they can see, right? |
eXtremeGossip |
|
|
-gary
Development Team Member
406 Posts |
Posted - 14 December 2004 : 13:00:59
|
It would go somewhere in the inc_func_common.asp file, but I'll let someone else do the implementation if they want since I don't have the time to dig into it right now.
Wether to use VB or RegEx is up to you. Some servers don't have the correct, or any, RegEx engine installed and some people just prefer doing it the VBScript way since you don't have to create an objects to use it. RegEx will be faster, though I wouldn't think by much in this case, but it is a cleaner solution. |
KawiForums.com
|
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 16 December 2004 : 01:18:55
|
I don't think the line of code in red is needed...
<%
txt = HideText(txt)
function HideText(txt)
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
Set regEx = New RegExp
regEx.Pattern = "\[hidden.*\/hidden\]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(txt)
HideText = regEx.Replace(txt, "")
end function
%>
this will also only replace one instance of the tag...
David [hidden]Jason[/hidden] Michael [hidden]Harris[/hidden] Ferrick
would show...
David Ferrick
However, I got the method I initially recommended to work using the [hidden=some text] syntax
Function HideText(fString)
Dim objRegExpr, Matches
Set objRegExpr = New regexp
objRegExpr.Pattern = "\[hidden=.*?\]"
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
Set Matches = objRegExpr.Execute(fString)
for each match in Matches
fString = Replace(fString, Match.Value, "")
next
Set Matches = Nothing
Set objRegExpr = Nothing
HideText = fString
End Function
|
|
Edited by - dayve on 16 December 2004 01:47:06 |
|
|
-gary
Development Team Member
406 Posts |
Posted - 16 December 2004 : 11:06:56
|
quote: Originally posted by dayve
I don't think the line of code in red is needed...
You're right, that was a cut and paste from an existing function I had and forgot to take it out.
quote:
this will also only replace one instance of the tag...
David [hidden]Jason[/hidden] Michael [hidden]Harris[/hidden] Ferrick
would show...
David Ferrick
Change it to non-greedy by using this instead. "\[hidden.*?\/hidden\]" |
KawiForums.com
|
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 16 December 2004 : 12:33:34
|
PERFECT!
<%
function HideText(txt)
Set regEx = New RegExp
regEx.Pattern = "\[hidden.*?\/hidden\]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(txt)
HideText = regEx.Replace(txt, "")
end function
Response.Write HideText("David [hidden]Jason[/hidden] Michael [hidden]Harris[/hidden] Ferrick")
%>
gives me David Michael Ferrick |
|
|
|
Jorrit787
Average Member
Netherlands
681 Posts |
Posted - 16 December 2004 : 16:55:38
|
Do I have to add the Response.Write Hidetext line to inc_func_common as well? |
eXtremeGossip |
|
|
|
Topic |
|