root/trunk/website/forums/includes/udf.cfm @ 5

Revision 5, 5.8 kB (checked in by DanWilson, 17 years ago)

Initial Commit Of ModelGlue? Website (upgrade to blogcfc 511)

Line 
1<cfsetting enablecfoutputonly=true>
2<!---
3        Name         : udf.cfm
4        Author       : Raymond Camden
5        Created      : June 01, 2004
6        Last Updated : February 21, 2007
7        History      : Added ActivateURL (rkc 2/11/05)
8                                   Added ParagraphFormat2 (rkc 3/28/05)
9                                   Added call to get rank (rkc 8/28/05)
10                                   Variety of a few new funcs (rkc 9/15/05)
11                                   Change isLoggedOn and the get user info stuff (rkc 7/12/06)
12                                   Moved some funcs into utils (rkc 11/3/06)
13                                   bd fix (rkc 2/21/07)
14        Purpose          :
15--->
16
17<cfscript>
18function isLoggedOn() {
19        return structKeyExists(session, "user");
20}
21request.udf.isLoggedOn = isLoggedOn;
22
23/**
24 * Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and new top-level domains).
25 * Update by David Kearns to support '
26 * SBrown@xacting.com pointing out regex still wasn't accepting ' correctly.
27 *
28 * @param str    The string to check. (Required)
29 * @return Returns a boolean.
30 * @author Jeff Guillaume (jeff@kazoomis.com)
31 * @version 2, August 15, 2002
32 
33 
34function IsEmail(str) {
35//supports new top level tlds
36if (REFindNoCase("^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$",str)) return TRUE;
37        else return FALSE;
38}
39request.udf.isEmail = isEmail;
40
41*/
42 
43function isValidUsername(str) {
44        if(reFindNoCase("[^a-z0-9]",str)) return false;
45        return true;
46}
47request.udf.isValidUsername = isValidUsername;
48
49/**
50 * Returns a XHTML compliant string wrapped with properly formatted paragraph tags.
51 *
52 * @param string         String you want XHTML formatted.
53 * @param attributeString        Optional attributes to assign to all opening paragraph tags (i.e. style=""font-family: tahoma"").
54 * @return Returns a string.
55 * @author Jeff Howden (jeff@members.evolt.org)
56 * @version 1.1, January 10, 2002
57 */
58function XHTMLParagraphFormat(string) {
59  var attributeString = '';
60  var returnValue = '';
61 
62  //added by me to support different line breaks
63  string = replace(string, chr(10) & chr(10), chr(13) & chr(10), "all");
64 
65  if(ArrayLen(arguments) GTE 2) attributeString = ' ' & arguments[2];
66  if(Len(Trim(string)))
67    returnValue = '<p' & attributeString & '>' & Replace(string, Chr(13) & Chr(10), '</p>' & Chr(13) & Chr(10) & '<p' & attributeString & '>', 'ALL') & '</p>';
68  return returnValue;
69}
70
71request.udf.XHTMLParagraphFormat = XHTMLParagraphFormat;
72
73
74/*
75 This function returns asc or desc, depending on if the current dir matches col
76*/
77function dir(col) {
78        if(isDefined("url.sort") and url.sort is col and isDefined("url.sortdir") and url.sortdir is "asc") return "desc";
79        return "asc";
80}
81request.udf.dir = dir;
82
83function headerLink(col) {
84        var str = "";
85        var colname = arguments.col;
86        var qs = cgi.query_string;
87       
88        if(arrayLen(arguments) gte 2) colname = arguments[2];
89       
90        // can't be too safe
91        if(not isDefined("url.sort")) url.sort = "";
92        if(not isDefined("url.sortdir")) url.sortdir = "";
93       
94        //clean qs
95        qs = reReplaceNoCase(qs, "&*sort=[^&]*","");
96        qs = reReplaceNoCase(qs, "&*sortdir=[^&]*","");
97        qs = reReplaceNoCase(qs, "&*page=[^&]*","");
98        qs = reReplaceNoCase(qs, "&*logout=[^&]*","");
99        qs = reReplaceNoCase(qs, "&{2,}","");
100        if(len(qs)) qs = qs & "&";
101       
102        if(url.sort is colname) str = str & "[";
103        str = str & "<a href=""#cgi.script_name#?#qs#sort=#urlEncodedFormat(colname)#&sortdir=" & dir(colname) & """>#col#</a>";
104        if(url.sort is colname) str = str & "]";
105        return str;
106}
107request.udf.headerLink = headerLink;
108</cfscript>
109
110<!--- provides a cached way to get user info --->
111<cffunction name="cachedUserInfo" returnType="struct" output="false">
112        <cfargument name="username" type="string" required="true">
113        <cfargument name="usecache" type="boolean" required="false" default="true">
114        <cfargument name="userid" type="boolean" required="false" default="false">
115        <cfset var userInfo = "">
116       
117        <cfif not isDefined("application.galleon.userCache")>
118                <cfset application.galleon.userCache = structNew()>
119                <cfset application.galleon.userCache_created = now()>
120        </cfif>
121       
122        <cfif dateDiff("h",application.galleon.userCache_created,now()) gte 2>
123                <cfset structClear(application.galleon.userCache)>
124                <cfset application.galleon.userCache_created = now()>
125        </cfif>
126
127        <!--- New argument, userid, if true, we first convert from ID to username --->
128        <cfif arguments.userid>
129                <cfset arguments.username = application.galleon.user.getUsernameFromID(arguments.username)>
130        </cfif>
131       
132        <cfif structKeyExists(application.galleon.userCache, arguments.username) and arguments.usecache>
133                <cfreturn duplicate(application.galleon.userCache[arguments.username])>
134        </cfif>
135       
136        <cfset userInfo = application.galleon.user.getUser(arguments.username)>
137        <!--- Get a rank for their posts --->
138        <cfset userInfo.rank = application.galleon.rank.getHighestRank(userInfo.postCount)>
139       
140        <cfset application.galleon.userCache[arguments.username] = userInfo>
141        <cfreturn userInfo>
142       
143</cffunction>
144<cfset request.udf.cachedUserInfo = cachedUserInfo>
145
146<cffunction name="querySortManual" returnType="query" output="false">
147        <cfargument name="query" type="query" required="true">
148        <cfargument name="column" type="string" required="true">
149        <cfargument name="direction" type="string" required="true">
150        <cfset var result = "">
151        <cfset var stickyStr = "sticky ">
152       
153        <cfif findNoCase("sticky", query.columnlist)>
154                <cfset stickyStr = stickyStr & "desc,">
155        <cfelse>
156                <cfset stickyStr = "">
157        </cfif>
158       
159        <cfif not listFindNoCase(query.columnList, column)>
160                <cfreturn query>
161        </cfif>
162       
163        <cfquery name="result" dbtype="query">
164        select          *
165        from            arguments.query
166        order by        #stickyStr# #arguments.column# #arguments.direction#
167        </cfquery>
168       
169        <cfreturn result>
170</cffunction>
171<cfset request.udf.querySort = querySortManual>
172       
173<cfsetting enablecfoutputonly=false>
Note: See TracBrowser for help on using the browser.