tjthay DNN Creative Magazine Subscriber
 Nuke Newbie Posts:8
 |
| 16 Jan 2008 11:55 AM |
|
Let me preface this post with the fact that I know very little about ASP programming so please go easy on me.
I have a Text/HTML module for an announcment section in a newsletter that we send via a third party. I am having trouble converting the encoded text which is stored in the HtmlText database. We have set up a Text/HTML module for the clients to enter their announcement text in - as I understand it the content from the module is converted (encoded) upon insertion into the HtmlText database for security reasons thereby converting the brackets, quotes etc. into different characters. As a result when I pull the data from db the text displays as the code. The following test content displays as follows (the actual code instead of html):
This is a test announcement.
This is a test link.
 
which displays literally as:
This is a test announcement.
This is a test link.
I found a function to convert the code back (decode) but it is not working. Here is the code that I am attempting to use:
<% DIM sql2 sql2 = "SELECT DesktopHtml FROM HtmlText WHERE ModuleID = 'x'"
DIM objRS2 Set objRS2 = Server.CreateObject("ADODB.Recordset") objRS2.Open sql2, objConn %> <% Dim sText Set sText= objRS2("DesktopHTML") %> <% Function HTMLDecode(sText) Dim I sText = Replace(sText, """, Chr(34)) sText = Replace(sText, "<" , Chr(60)) sText = Replace(sText, ">" , Chr(62)) sText = Replace(sText, "&" , Chr(38)) sText = Replace(sText, " ", Chr(32)) For I = 1 to 255 sText = Replace(sText, "" & I & ";", Chr(I)) Next HTMLDecode = sText End Function %> <% Response.Write(sText) %>
Any assistance with this issue is greatly appreciated.
Travis
|
|
|
|
|
leesykes DNN Creative Staff
 Nuke Master III Posts:3304
 |
|
tjthay DNN Creative Magazine Subscriber
 Nuke Newbie Posts:8
 |
| 17 Jan 2008 11:36 AM |
|
Lee,
Thanks. I want to try and pull directly from the database since we are pulling content from multiple sources to create a newsletter. In this way my clients can manage their own aspect of the newsletter and it will be dynamically generated on my end.
My research has shown that the Text/HTML module inputs the data into the db by encoding (I think through a Stored Procedure - but my knowledge of SQL is less than that of ASP) thereby converting certain characters like <, > and ".
I can easily pull the data back out but not sure why the replace function I am using is not working. Hopefully just missing something simple in the code. Probably could use the appropriate Stored Proc to decode although not sure how to implement that - it has to be something that the Text/HTML module is doing itself in order to display the code correctly but I wouldn't even know where to start to see how that module works. Maybe someone could point me in the right direction there.
Any help is appreciated.
Travis
|
|
|
|
|
jncraig DNN Creative Staff
 Nuke Master II Posts:2318

 |
| 17 Jan 2008 11:55 AM |
|
I took a quick look at some of the stored text for a couple of text/html modules. I don't think that the storage is for security purposes, but there are some characters that are replaced:
< < > > & &
If you change those, you'll probably get 95% or more of the changes that you need and the text will render correctly as html.
As for your substitutions, the Replace function is: Replace(Expression, WhatToReplace, ReplaceWithWhat)
So, I'd do things like: sText = Replace(sText, "<", "<") |
|
Joe Craig DNN Creative Support Subscribe to the website |
|
|
tjthay DNN Creative Magazine Subscriber
 Nuke Newbie Posts:8
 |
| 17 Jan 2008 12:11 PM |
|
Okay I think I got it. I was trying to implement a Function I found searching on Google. Removing the Function Name and end and just going with a plain replace seems to work. This is the code I am using now:
// Pulls String from DB and sets to sText // <% Dim sText Set sText= objRS2("DesktopHTML") %> // Replaces the characters // <% Function HTMLDecode(sText) // Removed this line // Dim I sText = Replace(sText, """, Chr(34)) sText = Replace(sText, "<" , Chr(60)) sText = Replace(sText, ">" , Chr(62)) sText = Replace(sText, "&" , Chr(38)) sText = Replace(sText, " ", Chr(32)) For I = 1 to 255 sText = Replace(sText, "" & I & ";", Chr(I)) Next End Function // Removed this line // %> // Writes the converted data to the page // <% Response.Write(sText) %>
Thanks to all for the ideas.
Travis
|
|
|
|
|
jncraig DNN Creative Staff
 Nuke Master II Posts:2318

 |
| 17 Jan 2008 12:13 PM |
|
| Oh, right! You defined the function, but you never called it. So much for quickly reading code... |
|
Joe Craig DNN Creative Support Subscribe to the website |
|
|
tjthay DNN Creative Magazine Subscriber
 Nuke Newbie Posts:8
 |
| 17 Jan 2008 12:15 PM |
|
Sorry, just noticed that the post is replacing the values with the html version which makes the posts look funny. Looks like I'm trying to replace a < with a <. Not sure how to post without the system converting.
Travis
|
|
|
|
|
tjthay DNN Creative Magazine Subscriber
 Nuke Newbie Posts:8
 |
| 17 Jan 2008 12:25 PM |
|
Joe,
Thanks. So just to complete the circle - you could leave the Function code in and use something like the following to display the converted text:
<% Response.Write(HTMLDecode(objRS2("DesktopHTML"))) %>
Thanks again for the help.
Travis
|
|
|
|
|
jncraig DNN Creative Staff
 Nuke Master II Posts:2318

 |
| 17 Jan 2008 12:29 PM |
|
| Yep! This would be useful if you plan to use the decode function in other places. |
|
Joe Craig DNN Creative Support Subscribe to the website |
|
|