source: extensions/FCKEditor/editor/filemanager/connectors/cfm/cf_io.cfm @ 3295

Last change on this file since 3295 was 3295, checked in by patdenice, 15 years ago

New extension added:
FCK Editor (2.0.a)

File size: 10.2 KB
Line 
1<cfsetting enablecfoutputonly="Yes">
2<!---
3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
4 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
5 *
6 * == BEGIN LICENSE ==
7 *
8 * Licensed under the terms of any of the following licenses at your
9 * choice:
10 *
11 *  - GNU General Public License Version 2 or later (the "GPL")
12 *    http://www.gnu.org/licenses/gpl.html
13 *
14 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15 *    http://www.gnu.org/licenses/lgpl.html
16 *
17 *  - Mozilla Public License Version 1.1 or later (the "MPL")
18 *    http://www.mozilla.org/MPL/MPL-1.1.html
19 *
20 * == END LICENSE ==
21 *
22 * This file include IO specific functions used by the ColdFusion Connector (MX 6.0 and above).
23 *
24--->
25
26<cffunction name="CombinePaths" returntype="String" output="true">
27        <cfargument name="sBasePath" required="true">
28        <cfargument name="sFolder" required="true">
29        <cfset sBasePath = RemoveFromEnd( sBasePath, "/" )>
30        <cfset sBasePath = RemoveFromEnd( sBasePath, "\" )>
31        <cfreturn sBasePath & "/" & RemoveFromStart( ARGUMENTS.sFolder, '/' )>
32</cffunction>
33
34<cffunction name="GetResourceTypePath" returntype="String" output="false">
35        <cfargument name="resourceType" required="true">
36        <cfargument name="sCommand" required="true">
37
38        <cfif ARGUMENTS.sCommand eq "QuickUpload">
39                <cfreturn REQUEST.Config['QuickUploadPath'][ARGUMENTS.resourceType]>
40        <cfelse>
41                <cfreturn REQUEST.Config['FileTypesPath'][ARGUMENTS.resourceType]>
42        </cfif>
43</cffunction>
44
45<cffunction name="GetResourceTypeDirectory" returntype="String" output="false">
46        <cfargument name="resourceType" required="true">
47        <cfargument name="sCommand" required="true">
48
49        <cfif ARGUMENTS.sCommand eq "QuickUpload">
50                <cfif isDefined( "REQUEST.Config.QuickUploadAbsolutePath" )
51                        and structkeyexists( REQUEST.Config.QuickUploadAbsolutePath, ARGUMENTS.resourceType )
52                        and Len( REQUEST.Config.QuickUploadAbsolutePath[ARGUMENTS.resourceType] )>
53                                <cfreturn REQUEST.Config.QuickUploadAbsolutePath[ARGUMENTS.resourceType]>
54                </cfif>
55
56                <cfreturn expandpath( REQUEST.Config.QuickUploadPath[ARGUMENTS.resourceType] )>
57        <cfelse>
58                <cfif isDefined( "REQUEST.Config.FileTypesAbsolutePath" )
59                        and structkeyexists( REQUEST.Config.FileTypesAbsolutePath, ARGUMENTS.resourceType )
60                        and Len( REQUEST.Config.FileTypesAbsolutePath[ARGUMENTS.resourceType] )>
61                                <cfreturn REQUEST.Config.FileTypesAbsolutePath[ARGUMENTS.resourceType]>
62                </cfif>
63
64                <cfreturn expandpath( REQUEST.Config.FileTypesPath[ARGUMENTS.resourceType] )>
65        </cfif>
66</cffunction>
67
68<cffunction name="GetUrlFromPath" returntype="String" output="false">
69        <cfargument name="resourceType" required="true">
70        <cfargument name="folderPath" required="true">
71        <cfargument name="sCommand" required="true">
72
73        <cfreturn CombinePaths( GetResourceTypePath( ARGUMENTS.resourceType, ARGUMENTS.sCommand ), ARGUMENTS.folderPath )>
74</cffunction>
75
76<cffunction name="RemoveExtension" output="false" returntype="String">
77        <cfargument name="fileName" required="true">
78        <cfset var pos = find( ".", reverse ( ARGUMENTS.fileName ) )>
79
80        <cfreturn mid( ARGUMENTS.fileName, 1, Len( ARGUMENTS.fileName ) - pos ) >
81</cffunction>
82
83<cffunction name="GetExtension" output="false" returntype="String">
84        <cfargument name="fileName" required="true">
85        <cfset var pos = find( ".", reverse ( ARGUMENTS.fileName ) )>
86
87        <cfif not pos>
88                <cfreturn "">
89        </cfif>
90
91        <cfreturn mid( ARGUMENTS.fileName, pos, Len( ARGUMENTS.fileName ) - pos ) >
92</cffunction>
93
94<cffunction name="ServerMapFolder" returntype="String" output="false">
95        <cfargument name="resourceType" required="true">
96        <cfargument name="folderPath" required="true">
97        <cfargument name="sCommand" required="true">
98
99        <!--- Get the resource type directory. --->
100        <cfset var sResourceTypePath = GetResourceTypeDirectory( ARGUMENTS.resourceType, ARGUMENTS.sCommand ) >
101        <!--- Ensure that the directory exists. --->
102        <cfset var sErrorMsg = CreateServerFolder( sResourceTypePath ) >
103
104        <cfif sErrorMsg neq ''>
105                <cfset SendError( 1, 'Error creating folder "' & sResourceTypePath & '" (' & sErrorMsg & ')' )>
106        </cfif>
107
108        <!--- Return the resource type directory combined with the required path. --->
109        <cfreturn CombinePaths( sResourceTypePath , ARGUMENTS.folderPath )>
110</cffunction>
111
112<cffunction name="GetParentFolder" returntype="string" output="false">
113        <cfargument name="folderPath" required="true">
114
115        <cfreturn rereplace(ARGUMENTS.folderPath, "[/\\\\][^/\\\\]+[/\\\\]?$", "")>
116</cffunction>
117
118<cffunction name="CreateServerFolder" returntype="String" output="false">
119        <cfargument name="folderPath">
120
121        <!--- Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms --->
122        <cfset folderPath = rereplace(ARGUMENTS.folderPath, "//+", "/", "all")>
123
124        <cfif directoryexists(ARGUMENTS.folderPath) or fileexists(ARGUMENTS.folderPath)>
125                <cfreturn "">
126        <cfelse>
127                <cftry>
128                        <cfdirectory action="create" mode="0755" directory="#ARGUMENTS.folderPath#">
129                <cfcatch type="any">
130                        <cfreturn CFCATCH.Message>
131                </cfcatch>
132                </cftry>
133        </cfif>
134
135        <cfreturn "">
136</cffunction>
137
138<cffunction name="IsAllowedExt" returntype="boolean" output="false">
139        <cfargument name="sExtension" required="true">
140        <cfargument name="resourceType" required="true">
141
142        <cfif isDefined( "REQUEST.Config.AllowedExtensions." & ARGUMENTS.resourceType )
143                        and listLen( REQUEST.Config.AllowedExtensions[ARGUMENTS.resourceType] )
144                        and not listFindNoCase( REQUEST.Config.AllowedExtensions[ARGUMENTS.resourceType], ARGUMENTS.sExtension )>
145                        <cfreturn false>
146        </cfif>
147
148        <cfif isDefined( "REQUEST.Config.DeniedExtensions." & ARGUMENTS.resourceType )
149                        and listLen( REQUEST.Config.DeniedExtensions[ARGUMENTS.resourceType] )
150                        and listFindNoCase( REQUEST.Config.DeniedExtensions[ARGUMENTS.resourceType], ARGUMENTS.sExtension )>
151                        <cfreturn false>
152        </cfif>
153
154        <cfreturn true>
155</cffunction>
156
157<cffunction name="IsAllowedType" returntype="boolean" output="false">
158        <cfargument name="resourceType">
159
160        <cfif not listFindNoCase( REQUEST.Config.ConfigAllowedTypes, ARGUMENTS.resourceType )>
161                <cfreturn false>
162        </cfif>
163
164        <cfreturn true>
165</cffunction>
166
167<cffunction name="IsAllowedCommand" returntype="boolean" output="true">
168        <cfargument name="sCommand" required="true" type="String">
169
170        <cfif not listFindNoCase( REQUEST.Config.ConfigAllowedCommands, ARGUMENTS.sCommand )>
171                <cfreturn false>
172        </cfif>
173
174        <cfreturn true>
175</cffunction>
176
177<cffunction name="GetCurrentFolder" returntype="String" output="true">
178        <cfset var sCurrentFolder = "/">
179
180        <cfif isDefined( "URL.CurrentFolder" )>
181                <cfset sCurrentFolder = URL.CurrentFolder>
182        </cfif>
183
184        <!--- Check the current folder syntax (must begin and start with a slash). --->
185        <cfif not refind( "/$", sCurrentFolder)>
186                <cfset sCurrentFolder = sCurrentFolder & "/">
187        </cfif>
188
189        <cfif not refind( "^/", sCurrentFolder )>
190                <cfset sCurrentFolder = "/" & sCurrentFolder>
191        </cfif>
192
193        <!--- Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms --->
194        <cfset sCurrentFolder = rereplace( sCurrentFolder, "//+", "/", "all" )>
195
196        <cfif find( "..", sCurrentFolder) or find( "\", sCurrentFolder) >
197                <cfset SendError( 102, "" )>
198        </cfif>
199
200        <cfreturn sCurrentFolder>
201</cffunction>
202
203<cffunction name="SanitizeFolderName" returntype="String" output="false">
204        <cfargument name="sNewFolderName" required="true">
205
206        <!--- Do a cleanup of the folder name to avoid possible problems --->
207        <!--- Remove . \ / | : ? * " < > and control characters --->
208        <cfset sNewFolderName = rereplace( sNewFolderName, '\.+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+|[[:cntrl:]]+', "_", "all" )>
209
210        <cfreturn sNewFolderName>
211</cffunction>
212
213<cffunction name="BinaryFileRead" returntype="String" output="true">
214        <cfargument name="fileName" required="true" type="string">
215        <cfargument name="bytes" required="true" type="Numeric">
216
217        <cfscript>
218        var chunk = "";
219        var fileReaderClass = "";
220        var fileReader = "";
221        var file = "";
222        var done = false;
223        var counter = 0;
224        var byteArray = "";
225
226        if( not fileExists( ARGUMENTS.fileName ) )
227        {
228                return "" ;
229        }
230
231        if (REQUEST.CFVersion gte 8)
232        {
233                 file  = FileOpen( ARGUMENTS.fileName, "readbinary" ) ;
234                 byteArray = FileRead( file, 1024 ) ;
235                 chunk = toString( toBinary( toBase64( byteArray ) ) ) ;
236                 FileClose( file ) ;
237        }
238        else
239        {
240                fileReaderClass = createObject("java", "java.io.FileInputStream");
241                fileReader = fileReaderClass.init(fileName);
242
243                while(not done)
244                {
245                        char = fileReader.read();
246                        counter = counter + 1;
247                        if ( char eq -1 or counter eq ARGUMENTS.bytes)
248                        {
249                                done = true;
250                        }
251                        else
252                        {
253                                chunk = chunk & chr(char) ;
254                        }
255                }
256        }
257        </cfscript>
258
259        <cfreturn chunk>
260</cffunction>
261
262<cffunction name="SendUploadResults" returntype="String" output="true">
263        <cfargument name="errorNumber" required="true" type="Numeric">
264        <cfargument name="fileUrl" required="false" type="String" default="">
265        <cfargument name="fileName" required="false" type="String" default="">
266        <cfargument name="customMsg" required="false" type="String" default="">
267
268        <!--- Minified version of the document.domain automatic fix script (#1919).
269        The original script can be found at _dev/domain_fix_template.js --->
270        <cfoutput>
271<script type="text/javascript">
272(function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();
273window.parent.OnUploadCompleted( #errorNumber#, "#JSStringFormat(fileUrl)#", "#JSStringFormat(fileName)#", "#JSStringFormat(customMsg)#" );
274</script>
275        </cfoutput>
276        <cfabort>
277</cffunction>
278
279<cffunction name="SanitizeFileName" returntype="String" output="false">
280        <cfargument name="sNewFileName" required="true">
281
282        <cfif isDefined("REQUEST.Config.ForceSingleExtension") and REQUEST.Config.ForceSingleExtension>
283                <cfset sNewFileName = rereplace( sNewFileName, '\.(?![^.]*$)', "_", "all" )>
284        </cfif>
285
286        <!--- Do a cleanup of the file name to avoid possible problems --->
287        <!--- Remove \ / | : ? * " < > and control characters --->
288        <cfset sNewFileName = rereplace( sNewFileName, '\\[.]+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+|[[:cntrl:]]+', "_", "all" )>
289
290        <cfreturn sNewFileName>
291</cffunction>
Note: See TracBrowser for help on using the repository browser.