I am trying to insert a Portion of HTML Code to be converted in BBCode and insert into the Database, Somehow I am making some mistake
I am trying with the following case. If the Div tag which is of class "Code", everything written HTML inside that will make the tags to be safe to display on the screen. My Code will show what I am trying to do: Also, I want that my Other Text should not get effected, that portion can include html too, but that will be parsed automatically
Here is the snippet
<cfscript>
function createCode(Text)
{
Text = Replace(Text, '&', '&', 'ALL');
Text = Replace(Text, '<', '[', 'ALL');
Text = Replace(Text, '>', ']', 'ALL');
Text = Replace(Text, Chr(13), '<br />', 'ALL');
return Text;
}
</cfscript>
<cfif arguments.structform.answer contains '<div class="code">'>
<cfset getText = '<div class="code">([\s\S]*)</div>'>
<cfset detectCode = #createCode(getText)#>
</cfif>
<cfdump var="#detectCode#" abort>
If this is about displaying HTML code as code - not interpreted by the browser - and saving + reading it with a database , I'm not sure why're you're trying to reinvent the wheel. ColdFusion has some built in functions like HTMLencode that will do the dirty work for you.
Related
I have a string retrieved from the database that can contain a series of codes in either {} or [] brackets as well as plain, user entered text. For example, each of the following would be possible values:
[code]
[code1][code2]
{code}
{code1}{code2}
{code1} Some user entered text. {code2}{code3} Some more user entered text.
Etc. etc.
What I need to do using ColdFusion is extract the codes within the {} and [] brackets so I can retrieve their descriptions from a database. For example:
{code1} Some user entered text. {code2}{code3} Some more user entered text.
Would become a list similar to:
{code1}|{code2}|{code3}
Normally I could just do something like REMatch but unfortunately I'm stuck doing this on a server running ColdFusion version 4.5 (groan) so my options are limited.
I'm thinking maybe I could do some Replaces on the string to convert it into a pipe delimited list that I can then easily process but I'm not sure if there might be a more straight forward approach? I'm not even really sure what a sensible way to process this using a Replace would be.
<cfset myString = "{code1} Some user entered text {code2}{code3} More user entered text" />
<cfset myArray = listToArray(myString, "{[") />
<cfloop index="i" from="1" to="#arrayLen(myArray)#">
<cfset myArray[i] = "{" & listFirst(myArray[i], "}]") & "}" />
</cfloop>
<cfdump var="#myArray#" />
<hr>
<cfset myList = arrayToList(myArray, "|") />
<cfdump var="#myList#" />
TryCF.com Gist:
https://trycf.com/gist/6035ddc5cd3daa81bc0943f1af33323a/lucee5?theme=monokai
I have attribute like this.
Example:
<div class="issue-document" id="assr_0335-5985_1991_num_76_1_1619" itemprop="hasPart" itemscope="" itemtype="https://facebook.com>
<cfset mystring = 'This is some text. It is true that <div class="issue-document" id="assr_0335-5985_1991_num_76_1_1619" itemprop="hasPart" itemscope="" itemtype="https://facebook.com">Harry Potter</div> is a good, but is better'>
<cfset MyReplace = ReReplaceNoCase(mystring,"<div [^>]*>","","ALL")>
<cfoutput><pre>Original string: #mystring#
Without link: #myreplace#</pre></cfoutput>
I need to remove only itemscope and itemprop like this rest of the attribute like id,class, style i don't want to remove using coldfusion in regular expression. Can any one please help to find the solution.
<cfset myReplace = reReplaceNoCase(mystring, '\b(itemscope|itemprop)="[^"]*"', "", "all")) />
https://trycf.com/gist/8d84d7d355f7c54e5533eeed22d097ba/acf2016?theme=monokai
I am trying to fix an issue with a certain [Coldfusion generated PAGE][1]. Please note, I have little knowledge of ColdFusion and how it works. So if you need more information, please let me know and I will try and track it down.
In the "How to Apply" section of the page there is meant to be included a URL for a certain website. However the page shows only the first part of the URL in clickable hyperlink format. Everything after the / is shown as plain text. Can you please suggest a solution ? Here is how the url looks on the page :
http://example.com/job-vacancies
Please note that the sections are extracted from the database and displayed dynamically in web pages. This image shows how the text looks in the database:
This is the content of job.cfm:
<cfset Application.controller.job()>
And this is the content of Application.cfm:
<cfapplication name="UK_AC_UEL_JOBSEARCH"
sessionmanagement="true"
setclientcookies="false"
setdomaincookies="false">
<cfscript>
function onRequestStart()
{
var formKeys = StructKeyList(Form);
var urlKeys = StructKeyList(URL);
var key = "";
var value = "";
var i = 0;
// ....
if (NOT StructKeyExists(Application, "controller"))
{
Application.controller = CreateObject("component", "uk.ac.uel.jobsearch.controller.Controller");
}
// ....
}
onRequestStart();
Update 1
I am still in the process of looking for the file that contains what actually renders the page in question. I was able to find Controller.cfc but it doesn't seem like it's directly responsible for rendering the page. After further searching, here is the code I believe renders that section of the page:
<div class="display-item last">
<div id="how-to-apply">
<h2>How to apply</h2>
<p>#formatWithLinks(Arguments.data.ApplicationProcedure)#</p>
<dl>
<dt>Closing date</dt>
<cfif Arguments.data.HasClosingDate>
<dd>#DateFormat(Arguments.data.ClosingDate, "D MMMM YYYY")#</dd>
<cfelse>
<dd>None: ongoing recruitment</dd>
</cfif>
</dl>
</div>
</div>
I am not sure what to change to tackle this issue. Any help would be greatly appreciated!
Hi guys just got to the bottom of this, the functions formatWithLinks is the key to solve this, it was found in the view.cfc file as #Leigh suggested ( thank you ) and here is the complete code of the function:
<cffunction name="formatWithLinks" output="false" returntype="string">
<cfargument name="input" />
<cfscript>
var output = Arguments.input;
/*var httpREWithProtocol = "(?x)
(
((https|http):\/\/) ## protocol
(
[a-zA-Z]{1}
([\w-]+\.)+
([a-zA-Z]{2,}) ## top level domain
) ## domain name
(:[\d]{1,5})? ## port number
((/?\w+/)+|/?)
(\w+\.[\w]{3,4})?
((\?\w+=\w+)?
(&\w+=\w+)*)?
)";*/
var httpREWithoutProtocol = "(?x)
(\s) ## Space requirement here means this won't match beginning of string
(
(
[a-zA-Z]{1}
([\w-]+\.)+
([a-zA-Z]{2,}) ## top level domain
) ## domain name
(:[\d]{1,5})? ## port number
((/?\w+/)+|/?)
(\w+\.[\w]{3,4})?
((\?\w+=\w+)?
(&\w+=\w+)*)?
)";
var httpREWithoutProtocolBeginningOfString = "(?x)
^ ## Match string here; I don't like doing it this way, but at least it works
(
(
[a-zA-Z]{1}
([\w-]+\.)+
([a-zA-Z]{2,}) ## top level domain
) ## domain name
(:[\d]{1,5})? ## port number
((/?\w+/)+|/?)
(\w+\.[\w]{3,4})?
((\?\w+=\w+)?
(&\w+=\w+)*)?
)";
var emailRE = "(?x)
(
[\S]+# ## user
[a-zA-Z]{1}
([\w-]+\.)+
([a-zA-Z]{2,})
)";
output = REReplace(output, "<[^>]*>", "", "all");
output = XMLFormat(output);
//output = REReplace(output, httpREWithProtocol, "\1", "all");
output = REReplaceNoCase(output,"(\bhttp://[a-z0-9\.\-_:~###%&/?+=]+)", "\1", "all");
output = REReplace(output, httpREWithoutProtocol, "\1\2", "all");
output = REReplace(output, httpREWithoutProtocolBeginningOfString, "\1", "all");
output = REReplace(output, emailRE, "\1", "all");
return output;
</cfscript>
</cffunction>
thank you everyone for trying to help. i greatly appreciate your efforts
The application.cfm is not where your problem is. Have a look in the cfm that actually renders the page. You'll probably find something like this...
http://example.com/#section#
Change that to...
http://example.com/#section#
And you should be golden. Note that everything between the hash tags is a dynamic ColdFusion variable. Your variable name will likely be very different.
I've got a cfsavecontent tag that saves a table. Later I use cffile to write the saved content to a file. When I look at that file, I see that there many blank lines inserted after <td> tags in the table; and few blank lines inserted after </tr> tags. (Although it doesn't do that where the code says <tr><td> </td></tr> all on one line.)
Presently I have a file which contains two of those tables. The tables are generated in a loop, and the output file is created with cffile append. This file has 915 lines in it of which maybe 30 are non-blank. All my subsequent code works correctly, but this is just test data. In the real world I could have 1000 or more tables, and I am concerned about the file size.
The code:
<cfset head1 = 'from = "moxware" '>
<cfset head2 = 'to = "#hrep.PersonEmail#" '>
<cfset head3 = 'replyto = "#replyto#" '>
<cfset head4 = 'subject = "#subject#" '>
<cfset head5 = 'type = "html" '>
<cfsavecontent variable = "abc">
<cfoutput>
#head1#
#head2#
#head3#
#head4#
#head5# >
#xyz#
</cfoutput>
</cfsavecontent>
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfmail"
mode = "777" >
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "#abc#"
mode = "777">
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "</cfmail>"
mode = "777" >
Re the xyz, I am reading it in from a file:
<cffile action = "read"
file = "/var/www/reports/moxrep/#reportname#.cfm"
variable = "xyz">
and the file looks like this:
<link rel="stylesheet" href="sample.css">
<link rel="stylesheet" type = "text/css" href ="betty.css"/>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font- family:georgia,serif">Dear Customer,</span></span></p>
We were so pleased that you have signed up for one of our programs. Apparently you live in the city of {{1. Additionally we observe that your were referred to us by {{2. Below please find a listing of what you signed up for.</span></span></p>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font- family:georgia,serif">{{r</span></span></p>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font-family:georgia,serif">Sincerely Yours,</span></span></p>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font-family:georgia,serif">John Jones<br />
President<br />
XYZ Corporation</span></span></p>
The file was created by a code generator, not me, so it's a bit cumbersome. Later in the code I replace everything starting with {{ ; in particular {{r gets replaced with a table, and that is where the additional space is coming from.
The append itself is not inserting any extra lines.
Does anyone know what is causing these extra blank lines in the file; and how to get rid of them?
Betty, typically you need to do this carefully if you want to avoid whitespace. In particular the use of cfoutput with a query will generate lines. So this code:
<table>
<cfoutput query="myquery">
<tr><td>#col1#</td><td>#col2#</td></tr>
</cfoutput>
</table>
will produce extra lines... but if you do this:
<cfsetting enablecfoutputonly="yes">
<cfoutput><table></cfoutput>
<cfloop query="myquery"><cfoutput><tr><td>#col1#</td><td>#col2#</td></tr></cfoutput></cfloop>
<cfoutput></table></cfoutput>
You would carefully control exactly what is allowed to be appended to the buffer. enableoutputonly does exactly what it says... it does not allow anything to "go to the buffer" unless it is enclosed in cfoutputs.
Hope this helps. As cameron says you should paste code for questions like this. That's where the answer will typically reside.
(you might also need to experiment with the "addnewline" attribute of cffile - depending on whether your problem is a line at the END of your file).
To answer your question regarding adding cfsetting... in your case you are writing CF code to a file that is then executed later (which by the way is not a great idea usually :). So in your first Append statement:
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfmail"
mode = "777" >
Change the "output" to be:
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfsetting enablecfoutputonly=""yes""/> <cfmail"
mode = "777" >
But Betty - you will still need to remove the line breaks from your cfsavecontent (if that's where your whitespace is coming from) because they actually ARE inside of a cfoutput. Also, your code that creates the table you are inserting might be at fault - and it is not listed here.
Finally, since this is cfmail take a look at this post regarding line breaks that may or may not have some bearing - but at least gives you one more piece of information :)
http://www.coldfusionmuse.com/index.cfm/2006/4/12/cfmail.linebreak
You may consider using cfprocessingdirective around your cfsavecontent. There is a setting in CF administrator that universally either compresses or retains unnecessary whitespace, "Enable Whitespace Management" - http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf3638e6-7ffc.html . Using the suppressWhiteSpace attribute of cfprocessingdirective, you can override this setting for a particular page or part of a page. So in your case:
<cfprocessingdirective suppressWhiteSpace="true">
<cfsavecontent variable="myvar">....
...
...
</cfsavecontent>
</cfprocessingdirective>
may help. Likewise, to ensure the retention of whitespace when building text emails, you'd use suppressWhiteSpace="false".
Cheers,
I have a report which is enclosed in a cfsavecontent tag.
<cfsavecontent variable = "testcust">
When I use
<cfoutput> #testcust# </cfoutput>
the report renders correctly. When I use cffile to save it to disk I lose the css formatting:
<cffile action = "write"
file = "/var/www/reports/testcust.cfm"
output = "#testcust#">
I can run testcust.cfm and it produces the report. All in-line styling is preserved. But formatting from the style sheet is not there. Does anyone know how to fix this?
You need to escape the html special characters. e.g < for < and > for >
So replace them before writing to file.