PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/view/sanitize.cfm

http://cfwheels.googlecode.com/
ColdFusion | 36 lines | 34 code | 2 blank | 0 comment | 1 complexity | 7cadf2e3e552c2fef2af36ed7f3be44b MD5 | raw file
 1<cffunction name="stripLinks" returntype="string" access="public" output="false" hint="Removes all links from an HTML string, leaving just the link text."
 2	examples=
 3	'
 4		##stripLinks("<strong>Wheels</strong> is a framework for <a href="http://www.adobe.com/products/coldfusion/">ColdFusion</a>.")##
 5		-> <strong>Wheels</strong> is a framework for ColdFusion.
 6	'
 7	categories="view-helper,sanitize" functions="stripTags,h">
 8	<cfargument name="html" type="string" required="true" hint="The HTML to remove links from.">
 9	<cfreturn REReplaceNoCase(arguments.html, "<a.*?>(.*?)</a>", "\1" , "all")>
10</cffunction>
11
12<cffunction name="stripTags" returntype="string" access="public" output="false" hint="Removes all HTML tags from a string."
13	examples=
14	'
15		##stripTags("<strong>Wheels</strong> is a framework for <a href="http://www.adobe.com/products/coldfusion/">ColdFusion</a>.")##
16		-> Wheels is a framework for ColdFusion.
17	'
18	categories="view-helper,sanitize" functions="stripLinks,h">
19	<cfargument name="html" type="string" required="true" hint="The HTML to remove tag markup from.">
20	<cfset var returnValue = "">
21	<cfset returnValue = REReplaceNoCase(arguments.html, "<\ *[a-z].*?>", "", "all")>
22	<cfset returnValue = REReplaceNoCase(returnValue, "<\ */\ *[a-z].*?>", "", "all")>
23	<cfreturn returnValue>
24</cffunction>
25
26<cffunction name="h" returntype="string" access="public" output="false" hint="Escapes unsafe HTML. Alias for your CFML engine's `XMLFormat()` function."
27	examples=
28	'
29		##h("<b>This "is" a test string & it should format properly</b>")##
30		-> &lt;b&gt;This &quot;is&quot; a test string &amp; it should format properly&lt;/b&gt;
31	'
32	categories="view-helper,sanitize" functions="stripLinks,stripTags">
33	<cfargument name="content" type="string" required="true">
34	<!--- you can't use argumentCollection --->
35	<cfreturn $htmlFormat(arguments.content)>
36</cffunction>