-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathudfs.cfm
305 lines (264 loc) · 9.18 KB
/
udfs.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<cfsilent>
<cfset Variables.udfs = true>
<cfif NOT StructKeyExists(variables,"da")>
<cffunction name="da" access="private" returntype="void" output="no">
<cfdump var="#Arguments#">
<cfabort>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"makeLink")>
<cffunction name="makeLink" access="public" returntype="string" output="no">
<cfargument name="Path" type="string" required="true">
<cfargument name="Args" type="struct" required="false">
<cfset var result = Arguments.Path>
<cfif StructCount(Arguments.Args)>
<cfset result = "#result#?#Struct2QueryString(Arguments.Args)#">
</cfif>
<cfreturn result>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"self")>
<cffunction name="self" access="public" returntype="string" output="no">
<cfset var sURL = QueryStringToStruct(CGI.QUERY_STRING)>
<cfset StructAppend(sURL,Arguments,true)>
<cfreturn makeLink(CGI.SCRIPT_NAME,sURL)>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"selflink")>
<cffunction name="selflink" access="public" returntype="string" output="no">
<cfargument name="label" type="string" required="true">
<cfargument name="args" type="struct" required="false">
<cfargument name="activeclass" type="string" required="false">
<cfset var result = '<a href="#self(ArgumentCollection=args)#"'>
<cfset var isActive = false>
<cfset var arg = "">
<cfscript>
if ( StructKeyHasLen(Arguments,"activeclass") ) {
isActive = true;
for ( arg in args ) {
if ( NOT ( StructKeyExists(URL,arg) AND args[arg] EQ URL[arg] ) ) {
isActive = false;
}
}
if ( isActive ) {
result = '#result# class="#Arguments.activeclass#"';
}
}
result = '#result#>#Arguments.label#</a>';
</cfscript>
<cfreturn result>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"selflink_li")>
<cffunction name="selflink_li" access="public" returntype="string" output="no">
<cfargument name="label" type="string" required="true">
<cfargument name="args" type="struct" required="false">
<cfargument name="activeclass" type="string" required="false">
<cfset var result = '<li'>
<cfset var isActive = false>
<cfset var arg = "">
<cfscript>
if ( StructKeyHasLen(Arguments,"activeclass") ) {
isActive = true;
for ( arg in args ) {
if ( NOT ( StructKeyExists(URL,arg) AND args[arg] EQ URL[arg] ) ) {
isActive = false;
}
}
if ( isActive ) {
result = '#result# class="#Arguments.activeclass#"';
}
}
result = '#result#><a href="#self(ArgumentCollection=args)#">#Arguments.label#</a></li>';
</cfscript>
<cfreturn result>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"ListToHTML")>
<cffunction name="ListToHTML" access="public" returntype="string" output="false" hint="I return a list as an HTML list.">
<cfargument name="list" type="string" required="true">
<cfargument name="delimiter" type="string" default=",">
<cfscript>
var result = "";
var aItems = 0;
var ii = 0;
if ( Len(Trim(Arguments.list)) ) {
aItems = ListToArray(list,delimiter);
result = "<ul>";
for ( ii=1; ii LTE ArrayLen(aItems); ii++ ) {
result = "#result#<li>#aItems[ii]#</li>";
}
result = "#result#</ul>";
}
return result;
</cfscript>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"ListIntegers")>
<cfscript>
function ListIntegers(list) { return ReReplaceNoCase(ReReplaceNoCase(list,'[^0-9]',',','ALL'),',{2,}',',','ALL'); }
</cfscript>
</cfif>
<cfif NOT StructKeyExists(variables,"makeCompName")>
<cfscript>
function makeCompName(str) { return variables.Manager.makeCompName(str); }
</cfscript>
</cfif>
<cfif NOT StructKeyExists(variables,"QueryAddRowStruct")>
<cfscript>
function QueryAddRowStruct(query,struct) {
var cols = Arguments.query.ColumnList;
var col = "";
QueryAddRow(query);
for ( col in Arguments.struct ) {
if ( ListFindNoCase(cols,col) ) {
querySetCell(Arguments.query, col, Arguments.struct[col]);
}
}
}
</cfscript>
</cfif>
<cfif false AND NOT StructKeyExists(variables,"QueryRowToStruct")>
<cfscript>
/**
* Makes a row of a query into a structure.
*
* @param query The query to work with.
* @param row Row number to check. Defaults to row 1.
* @return Returns a structure.
* @author Nathan Dintenfass ([email protected])
* @version 1, December 11, 2001
*/
function QueryRowToStruct(query){
//by default, do this to the first row of the query
var row = 1;
//a var for looping
var ii = 1;
//the cols to loop over
var cols = listToArray(query.columnList);
//the struct to return
var stReturn = structnew();
//if there is a second argument, use that for the row number
if(arrayLen(arguments) GT 1)
row = arguments[2];
//loop over the cols and build the struct from the query row
for(ii = 1; ii lte arraylen(cols); ii = ii + 1){
stReturn[cols[ii]] = query[cols[ii]][row];
}
//return the struct
return stReturn;
}
</cfscript>
</cfif>
<cfif NOT StructKeyExists(variables,"QueryToArray")>
<!--- https://www.bennadel.com/blog/124-ask-ben-converting-a-query-to-an-array.htm --->
<cffunction name="QueryToArray" access="public" returntype="array" output="false" hint="This turns a query into an array of structures.">
<!--- Define arguments. --->
<cfargument name="Data" type="query" required="yes" />
<cfscript>
// Define the local scope.
var LOCAL = StructNew();
// Get the column names as an array.
LOCAL.Columns = ListToArray( ARGUMENTS.Data.ColumnList );
// Create an array that will hold the query equivalent.
LOCAL.QueryArray = ArrayNew( 1 );
// Loop over the query.
for (LOCAL.RowIndex = 1 ; LOCAL.RowIndex LTE ARGUMENTS.Data.RecordCount ; LOCAL.RowIndex = (LOCAL.RowIndex + 1)){
// Create a row structure.
LOCAL.Row = StructNew();
// Loop over the columns in this row.
for (LOCAL.ColumnIndex = 1 ; LOCAL.ColumnIndex LTE ArrayLen( LOCAL.Columns ) ; LOCAL.ColumnIndex = (LOCAL.ColumnIndex + 1)){
// Get a reference to the query column.
LOCAL.ColumnName = LOCAL.Columns[ LOCAL.ColumnIndex ];
// Store the query cell value into the struct by key.
LOCAL.Row[ LOCAL.ColumnName ] = ARGUMENTS.Data[ LOCAL.ColumnName ][ LOCAL.RowIndex ];
}
// Add the structure to the query array.
ArrayAppend( LOCAL.QueryArray, LOCAL.Row );
}
// Return the array equivalent.
return( LOCAL.QueryArray );
</cfscript>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"QueryStringToStruct")>
<cffunction name="QueryStringToStruct" access="private" returntype="any" output="false" hint="I accept a URL query string and return it as a structure.">
<cfargument name="querystring" type="string" required="true" hint="I am the query string for which to parse.">
<cfscript>
var aList = ListToArray(Arguments.querystring,"&");
return aList.reduce(function(result,item,index){
result[ListFirst(item,"=")] = ListRest(item,"=");
return result;
},{});
</cfscript>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"Struct2QueryString")>
<cffunction name="Struct2QueryString" access="private" returntype="string" output="false" hint="I accept a structure and return it as a URL query string.">
<cfargument name="struct" type="struct" required="true" hint="I am the struct to turn into a query string.">
<cfscript>
return Arguments.struct.reduce(function(result, key, value) {
result = result?:"";
return ListAppend(result,"#LCase(key)#=#value#","&");
});
</cfscript>
</cffunction>
</cfif>
<cfif NOT StructKeyExists(variables,"StructKeyHasLen")>
<cfscript>
function StructKeyHasLen(struct,key){
return ( StructKeyExists(Arguments.struct,key) AND Len(Trim(Arguments.struct[key])) );
}
</cfscript>
</cfif>
<cfif NOT StructKeyExists(variables,"StructKeyHasVal")>
<cfscript>
function StructKeyHasVal(struct,key){
return ( StructKeyExists(Arguments.struct,key) AND Val(Arguments.struct[key]) );
}
</cfscript>
</cfif>
<cfif NOT StructKeyExists(variables,"TrimAll")>
<cfscript>
function TrimAll(str) {
var wschars = "160,194";
str = Trim(str);
//Trim right
while ( Len(str) AND ListFindNoCase(wschars,Asc(Right(str,1))) ) {
if ( Len(str) GT 1 ) {
str = Trim(Left(str,Len(str)-1));
} else {
return "";
}
}
//Trim left
while ( Len(str) AND ListFindNoCase(wschars,Asc(Left(str,1))) ) {
if ( Len(str) GT 1 ) {
str = Trim(Right(str,Len(str)-1));
} else {
return "";
}
}
return str;
}
</cfscript>
</cfif>
<!--- If this is called as a custom tag, then make the functions available to the caller. --->
<cfif StructKeyExists(Variables,"ThisTag")>
<!--- Optional "returnvar" argument to put functions into the specified variable. --->
<cfif StructKeyHasLen(Attributes,"returnvar")>
<cfif NOT StructKeyExists(Caller,Attributes.returnvar)>
<cfset Caller[Attributes.returnvar] = {}>
</cfif>
<cfset scope = Caller[Attributes.returnvar]>
<cfelse>
<!--- If no returnvar specified, then just put them in Variables scope on the calling page. --->
<cfset scope = Caller>
</cfif>
<cfloop collection="#Variables#" item="varname">
<cfif isCustomFunction(Variables[varname]) AND NOT StructKeyExists(scope,varname)>
<cfset scope[varname] = Variables[varname]>
</cfif>
</cfloop>
</cfif>
</cfsilent>