| 1 | <cfscript> |
|---|
| 2 | function titleCase(str) { |
|---|
| 3 | return uCase(left(str,1)) & right(str,len(str)-1); |
|---|
| 4 | } |
|---|
| 5 | |
|---|
| 6 | /** |
|---|
| 7 | * Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and new top-level domains). |
|---|
| 8 | * Update by David Kearns to support ' |
|---|
| 9 | * SBrown@xacting.com pointing out regex still wasn't accepting ' correctly. |
|---|
| 10 | * More TLDs |
|---|
| 11 | * Version 4 by P Farrel, supports limits on u/h |
|---|
| 12 | * Added mobi |
|---|
| 13 | * v6 more tlds |
|---|
| 14 | * |
|---|
| 15 | * @param str The string to check. (Required) |
|---|
| 16 | * @return Returns a boolean. |
|---|
| 17 | * @author Jeff Guillaume (SBrown@xacting.comjeff@kazoomis.com) |
|---|
| 18 | * @version 6, July 29, 2008 |
|---|
| 19 | * Note this is different from CFLib as it has the "allow +" support |
|---|
| 20 | */ |
|---|
| 21 | function isEmail(str) { |
|---|
| 22 | return (REFindNoCase("^['_a-z0-9-]+(\.['_a-z0-9-]+)*(\+['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|asia|biz|cat|coop|info|museum|name|jobs|post|pro|tel|travel|mobi))$",arguments.str) AND len(listGetAt(arguments.str, 1, "@")) LTE 64 AND |
|---|
| 23 | len(listGetAt(arguments.str, 2, "@")) LTE 255) IS 1; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | function isLoggedIn() { |
|---|
| 27 | return structKeyExists(session,"loggedin"); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * An "enhanced" version of ParagraphFormat. |
|---|
| 32 | * Added replacement of tab with nonbreaking space char, idea by Mark R Andrachek. |
|---|
| 33 | * Rewrite and multiOS support by Nathan Dintenfas. |
|---|
| 34 | * |
|---|
| 35 | * @param string The string to format. (Required) |
|---|
| 36 | * @return Returns a string. |
|---|
| 37 | * @author Ben Forta (ben@forta.com) |
|---|
| 38 | * @version 3, June 26, 2002 |
|---|
| 39 | */ |
|---|
| 40 | function ParagraphFormat2(str) { |
|---|
| 41 | //first make Windows style into Unix style |
|---|
| 42 | str = replace(str,chr(13)&chr(10),chr(10),"ALL"); |
|---|
| 43 | //now make Macintosh style into Unix style |
|---|
| 44 | str = replace(str,chr(13),chr(10),"ALL"); |
|---|
| 45 | //now fix tabs |
|---|
| 46 | str = replace(str,chr(9)," ","ALL"); |
|---|
| 47 | //now return the text formatted in HTML |
|---|
| 48 | return replace(str,chr(10),"<br />","ALL"); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * A quick way to test if a string is a URL |
|---|
| 53 | * |
|---|
| 54 | * @param stringToCheck The string to check. |
|---|
| 55 | * @return Returns a boolean. |
|---|
| 56 | * @author Nathan Dintenfass (nathan@changemedia.com) |
|---|
| 57 | * @version 1, November 22, 2001 |
|---|
| 58 | */ |
|---|
| 59 | function isURL(stringToCheck){ |
|---|
| 60 | return REFindNoCase("^(((https?:|ftp:|gopher:)\/\/))[-[:alnum:]\?%,\.\/&##!@:=\+~_]+[A-Za-z0-9\/]$",stringToCheck) NEQ 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Converts a byte value into kb or mb if over 1,204 bytes. |
|---|
| 65 | * |
|---|
| 66 | * @param bytes The number of bytes. (Required) |
|---|
| 67 | * @return Returns a string. |
|---|
| 68 | * @author John Bartlett (jbartlett@strangejourney.net) |
|---|
| 69 | * @version 1, July 31, 2005 |
|---|
| 70 | */ |
|---|
| 71 | function KBytes(bytes) { |
|---|
| 72 | var b=0; |
|---|
| 73 | |
|---|
| 74 | if(arguments.bytes lt 1024) return trim(numberFormat(arguments.bytes,"9,999")) & " bytes"; |
|---|
| 75 | |
|---|
| 76 | b=arguments.bytes / 1024; |
|---|
| 77 | |
|---|
| 78 | if (b lt 1024) { |
|---|
| 79 | if(b eq int(b)) return trim(numberFormat(b,"9,999")) & " KB"; |
|---|
| 80 | return trim(numberFormat(b,"9,999.9")) & " KB"; |
|---|
| 81 | } |
|---|
| 82 | b= b / 1024; |
|---|
| 83 | if (b eq int(b)) return trim(numberFormat(b,"999,999,999")) & " MB"; |
|---|
| 84 | return trim(numberFormat(b,"999,999,999.9")) & " MB"; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * Returns a relative path from the current template to an absolute file path. |
|---|
| 89 | * |
|---|
| 90 | * @param abspath Absolute path. (Required) |
|---|
| 91 | * @return Returns a string. |
|---|
| 92 | * @author Isaac Dealey (info@turnkey.to) |
|---|
| 93 | * @version 1, May 2, 2003 |
|---|
| 94 | */ |
|---|
| 95 | function getRelativePath(abspath){ |
|---|
| 96 | var aHere = listtoarray(expandPath("/"),"\/"); |
|---|
| 97 | var aThere = ""; var lenThere = 0; |
|---|
| 98 | var aRel = ArrayNew(1); var x = 0; |
|---|
| 99 | var newpath = ""; |
|---|
| 100 | |
|---|
| 101 | aThere = ListToArray(abspath,"\/"); lenThere = arraylen(aThere); |
|---|
| 102 | |
|---|
| 103 | for (x = 1; x lte arraylen(aHere); x = x + 1) { |
|---|
| 104 | if (x GT lenThere OR comparenocase(aHere[x],aThere[x])) { |
|---|
| 105 | ArrayPrepend(aRel,".."); if (x lte lenThere) { ArrayAppend(aRel,aThere[x]); } |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | for (; x lte arraylen(aThere); x = x + 1) { ArrayAppend(aRel,aThere[x]); } |
|---|
| 110 | |
|---|
| 111 | newpath = "/" & ArrayToList(aRel,"/"); |
|---|
| 112 | |
|---|
| 113 | return newpath; |
|---|
| 114 | } |
|---|
| 115 | Request.getRelativePath = getRelativePath; |
|---|
| 116 | |
|---|
| 117 | </cfscript> |
|---|
| 118 | |
|---|
| 119 | <!--- |
|---|
| 120 | This UDF from Steven Erat, http://www.talkingtree.com/blog |
|---|
| 121 | ---> |
|---|
| 122 | <cffunction name="replaceLinks" access="public" output="yes" returntype="string"> |
|---|
| 123 | <cfargument name="input" required="Yes" type="string"> |
|---|
| 124 | <cfargument name="linkmax" type="numeric" required="false" default="50"> |
|---|
| 125 | <cfscript> |
|---|
| 126 | var inputReturn = arguments.input; |
|---|
| 127 | var pattern = ""; |
|---|
| 128 | var urlMatches = structNew(); |
|---|
| 129 | var inputCopy = arguments.input; |
|---|
| 130 | var result = ""; |
|---|
| 131 | var rightStart = ""; |
|---|
| 132 | var rightInputCopyLen = ""; |
|---|
| 133 | var targetNameMax = ""; |
|---|
| 134 | var targetLinkName = ""; |
|---|
| 135 | var i = ""; |
|---|
| 136 | |
|---|
| 137 | pattern = "(((https?:|ftp:|gopher:)\/\/)|(www\.|ftp\.))[-[:alnum:]\?%,\.\/&##!;@:=\+~_]+[A-Za-z0-9\/]"; |
|---|
| 138 | |
|---|
| 139 | while (len(inputCopy)) { |
|---|
| 140 | result = refind(pattern,inputCopy,1,'true'); |
|---|
| 141 | if (result.pos[1]){ |
|---|
| 142 | match = mid(inputCopy,result.pos[1],result.len[1]); |
|---|
| 143 | urlMatches[match] = ""; |
|---|
| 144 | rightStart = result.len[1] + result.pos[1]; |
|---|
| 145 | rightInputCopyLen = len(inputCopy)-rightStart; |
|---|
| 146 | if (rightInputCopyLen GT 0){ |
|---|
| 147 | inputCopy = right(inputCopy,rightInputCopyLen); |
|---|
| 148 | } else break; |
|---|
| 149 | } else break; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | //convert back to array |
|---|
| 153 | urlMatches = structKeyArray(urlMatches); |
|---|
| 154 | |
|---|
| 155 | targetNameMax = arguments.linkmax; |
|---|
| 156 | for (i=1; i LTE arraylen(urlMatches);i=i+1) { |
|---|
| 157 | targetLinkName = urlMatches[i]; |
|---|
| 158 | if (len(targetLinkName) GTE targetNameMax) { |
|---|
| 159 | targetLinkName = left(targetLinkName,targetNameMax) & "..."; |
|---|
| 160 | } |
|---|
| 161 | inputReturn = replace(inputReturn,urlMatches[i],'<a href="#urlMatches[i]#" target="_blank">#targetLinkName#</a>',"all"); |
|---|
| 162 | } |
|---|
| 163 | </cfscript> |
|---|
| 164 | <cfreturn inputReturn> |
|---|
| 165 | </cffunction> |
|---|