Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 Variables in code?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

ADSaunders
Starting Member

United Kingdom
22 Posts

Posted - 26 March 2003 :  04:38:10  Show Profile
I'm still developing/testing my forum, working my way through the mods I need to install.
I've just implemented OnewayMule's forum rules mod, and was populating the rules table when a thought struck me. What if the Boss doesn't like the forum name I've chosen? I'd have to go through all of the rules I had implemented, and change them to reflect the new name.
Now, wouldn't it be nice if we had a (for example) [var]...[/var]code option in which we could insert one of the application variables? Then All of the rules could contain for example:
[var]strForumTitle[/var]
and the rules would reflect the current forum title if it were ever to be changed. I can see some use of this also in the post/reply functionality, isn't Snitz Forums 2000 itself likely to change it's name?
It would be even nicer if the post/reply page contained a drop-down box listing all of the application variables??
I'd have a go at this myself if I had time, but though I'm a competent programmer (near 30 years), I'm still fairly new to ASP, and even newer to SQL!

..Alan

ADSaunders
Starting Member

United Kingdom
22 Posts

Posted - 26 March 2003 :  05:53:56  Show Profile
Well, despite my inexperience with SQL, I found that the actual code is fairly straightforward. The following snippet does the correct substitutions, now where should I put it? I suspect that early in the cleancode function in inc_func_posting.asp would be best, then anything in the substitution strings themselves that need further cleaning would be handled. Any comments?
<!--#INCLUDE FILE="config.asp" -->
<%
'# replace  [var] ... [/var] code              
Dim sSubject                    
sSubject = "[var]strForumTitle[/var] is copyright © [var]strCopyright[/var]"

	set my_Conn = Server.CreateObject("ADODB.Connection")
	my_Conn.Errors.Clear
	Err.Clear                 
	
	my_Conn.Open strConnString

	strSql = "SELECT * FROM " & strTablePrefix & "CONFIG_NEW "

	set rsConfig = my_Conn.Execute (strSql)

	do while not rsConfig.EOF
		sSubject = Replace(sSubject,"[var]" &  TRIM(rsConfig("C_VARIABLE")) & "[/var]",Trim(rsConfig("C_VALUE")) ,1,-1,1)
		rsConfig.MoveNext
	loop
	rsConfig.close
%>

.. Alan

Edited by - ADSaunders on 26 March 2003 06:01:27
Go to Top of Page

Hamlin
Advanced Member

United Kingdom
2386 Posts

Posted - 26 March 2003 :  06:09:35  Show Profile
One comment

The contents of the FORUM_CONFIG_NEW table are loaded into application variables, and in config.asp they are placed in script level variables, that can be accessed anywhere in the forum code. So you do not need to open a recordset and load the values as they are already available.

It is an interesting idea though

Edited by - Hamlin on 26 March 2003 06:10:15
Go to Top of Page

ADSaunders
Starting Member

United Kingdom
22 Posts

Posted - 26 March 2003 :  07:05:14  Show Profile
Thanks Hamlin,
Ah.. But wouldn't I need a rake of
sSubject = replace(sSubject,"[var]strForumTitle[/var]", strForumTitle)
sSubject = replace(sSubject,"[var]strCopyright[/var]", strCopyright)
... etc
, and what about then having to amend it when new mods added new variables??
.. Alan
Go to Top of Page

Hamlin
Advanced Member

United Kingdom
2386 Posts

Posted - 26 March 2003 :  07:21:56  Show Profile
Yes, and yes that would make it harder to modify, I see where your going now, you literally wanted all the variables.

Ok then I'll shut up now and let you get on with what you were doing

As for your original where to put it question I don't have access to the code right now, but the cleancode function, that deals with the other forum code and smiles would be the correct place I suppose.

Edited by - Hamlin on 26 March 2003 07:22:52
Go to Top of Page

ADSaunders
Starting Member

United Kingdom
22 Posts

Posted - 26 March 2003 :  09:21:27  Show Profile
CleanCode doesn't seem to be the place for this, everything's reversed, the forum code shows up in the msg and the preview, the substituted code in the edit pane.
Any more ideas?? how about the chkstring function.
.. Alan
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 26 March 2003 :  10:19:57  Show Profile
It might be better (from a performance point of view) to read all the data into an array and store in an application variable rather than query the database all the time.
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 26 March 2003 :  23:18:48  Show Profile  Visit Gremlin's Homepage
Untested, but something like this should work


<!--#INCLUDE FILE="config.asp" -->
<%
'# replace  [var] ... [/var] code              
Dim sSubject                    
sSubject = "[var]strForumTitle[/var] is copyright © [var]strCopyright[/var]"

For each Variable in Application.Contents
  sSubject = Replace(sSubject,"[var]" &  ChkString(Variable, "display") & "[/var]",chkString(CStr(Application.Contents(Variable)), "display") ,1,-1,1)
Next
%>


Kiwihosting.Net - The Forum Hosting Specialists

Edited by - Gremlin on 27 March 2003 05:53:16
Go to Top of Page

ADSaunders
Starting Member

United Kingdom
22 Posts

Posted - 27 March 2003 :  03:56:03  Show Profile
Hi Gremlin,
I'd already worked out that they should all be in a collection aleady, I've been working on Application.Contents with some success, but yours looks like less code, I'll try it.
Regards .. Alan
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 27 March 2003 :  05:51:25  Show Profile  Visit Gremlin's Homepage
Yeah youve just pointed out an error in my code there too, they're in App variable not Session

Change reference to Session.Contents to Application.Contents should do it.

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 27 March 2003 :  06:02:07  Show Profile  Visit Gremlin's Homepage
Decided to test it out myself

The following works ok for me, but note my forum is in the root directory of the website so the variables are all called /strxxx etc the code in red handles this by removing the leading "/". If you forum is say in /forum then you'll need to cater for that as well.


<!--#INCLUDE FILE="config.asp"-->
<!--#INCLUDE FILE="inc_header.asp" -->
<%
'# replace  [var] ... [/var] code              
Dim sSubject                    
sSubject = "[var]strForumTitle[/var] is copyright © [var]strCopyright[/var]"

For each Variable in Application.Contents

  sSubject = Replace(sSubject,"[var]" & ChkString(Right(Variable,Len(Variable)-1), "display") & "[/var]",chkString(CStr(Application.Contents(Variable)), "display") ,1,-1,1)
Next

Response.Write sSubject

%>

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page

ADSaunders
Starting Member

United Kingdom
22 Posts

Posted - 27 March 2003 :  06:08:17  Show Profile
Well, Yur 'tis
This is now working code. I have been doing some work on providing a drop-down selector A La font & color, but I can't see a use for most of them, just some of the strings in the early ones. If there's any interest, I'll post my code.

This change is pretty trivial to implement, just a single smallish block of code to be inserted into the FormatStr function in inc_func_common.asp:

Look for:
function FormatStr(fString)
  on Error resume next
  fString = Replace(fString, CHR(13), "")
  'fString = Replace(fString, CHR(10) & CHR(10), "<br /><br />")
  fString = Replace(fString, CHR(10), "<br />")
  if strBadWordFilter = 1 or strBadWordFilter = "1" then
    fString = ChkBadWords(fString)
  end if

and insert:
'## replace  [var] ... [/var] code  
if strAllowForumCode = "1" then
  if instr(fString, "[var]") > 0 then ' Don't bother if it's not there
    dim varitem
    for each varitem in Application.contents
      if MID(varitem,1,len(strCookieurl)) = strCookieURL then ' Check it's one we created
        fString = Replace(fString, "[var]" &  TRIM(MID(varitem, len(strCookieURL)+1)) & "[/var]", TRIM(Application.contents varItem)) ,1,-1,1)
      end if
    next
  end if
end if
'## END of replace  [var] ... [/var] code              

before the check for bad words.
(This will stop anyone trying to insert [var]StrBadWords[/var].. well it won't stop them, but they'll be filtered.)

..Alan
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.77 seconds. Powered By: Snitz Forums 2000 Version 3.4.07