1 | ##### |
---|
2 | # FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
3 | # Copyright (C) 2003-2009 Frederico Caldeira Knabben |
---|
4 | # |
---|
5 | # == BEGIN LICENSE == |
---|
6 | # |
---|
7 | # Licensed under the terms of any of the following licenses at your |
---|
8 | # choice: |
---|
9 | # |
---|
10 | # - GNU General Public License Version 2 or later (the "GPL") |
---|
11 | # http://www.gnu.org/licenses/gpl.html |
---|
12 | # |
---|
13 | # - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
---|
14 | # http://www.gnu.org/licenses/lgpl.html |
---|
15 | # |
---|
16 | # - Mozilla Public License Version 1.1 or later (the "MPL") |
---|
17 | # http://www.mozilla.org/MPL/MPL-1.1.html |
---|
18 | # |
---|
19 | # == END LICENSE == |
---|
20 | # |
---|
21 | # This is the File Manager Connector for Perl. |
---|
22 | ##### |
---|
23 | |
---|
24 | sub GetFolders |
---|
25 | { |
---|
26 | |
---|
27 | local($resourceType, $currentFolder) = @_; |
---|
28 | |
---|
29 | # Map the virtual path to the local server path. |
---|
30 | $sServerDir = &ServerMapFolder($resourceType, $currentFolder); |
---|
31 | print "<Folders>"; # Open the "Folders" node. |
---|
32 | |
---|
33 | opendir(DIR,"$sServerDir"); |
---|
34 | @files = grep(!/^\.\.?$/,readdir(DIR)); |
---|
35 | closedir(DIR); |
---|
36 | |
---|
37 | foreach $sFile (@files) { |
---|
38 | if($sFile != '.' && $sFile != '..' && (-d "$sServerDir$sFile")) { |
---|
39 | $cnv_filename = &ConvertToXmlAttribute($sFile); |
---|
40 | print '<Folder name="' . $cnv_filename . '" />'; |
---|
41 | } |
---|
42 | } |
---|
43 | print "</Folders>"; # Close the "Folders" node. |
---|
44 | } |
---|
45 | |
---|
46 | sub GetFoldersAndFiles |
---|
47 | { |
---|
48 | |
---|
49 | local($resourceType, $currentFolder) = @_; |
---|
50 | # Map the virtual path to the local server path. |
---|
51 | $sServerDir = &ServerMapFolder($resourceType,$currentFolder); |
---|
52 | |
---|
53 | # Initialize the output buffers for "Folders" and "Files". |
---|
54 | $sFolders = '<Folders>'; |
---|
55 | $sFiles = '<Files>'; |
---|
56 | |
---|
57 | opendir(DIR,"$sServerDir"); |
---|
58 | @files = grep(!/^\.\.?$/,readdir(DIR)); |
---|
59 | closedir(DIR); |
---|
60 | |
---|
61 | foreach $sFile (@files) { |
---|
62 | if($sFile ne '.' && $sFile ne '..') { |
---|
63 | if(-d "$sServerDir$sFile") { |
---|
64 | $cnv_filename = &ConvertToXmlAttribute($sFile); |
---|
65 | $sFolders .= '<Folder name="' . $cnv_filename . '" />' ; |
---|
66 | } else { |
---|
67 | ($iFileSize,$refdate,$filedate,$fileperm) = (stat("$sServerDir$sFile"))[7,8,9,2]; |
---|
68 | if($iFileSize > 0) { |
---|
69 | $iFileSize = int($iFileSize / 1024); |
---|
70 | if($iFileSize < 1) { |
---|
71 | $iFileSize = 1; |
---|
72 | } |
---|
73 | } |
---|
74 | $cnv_filename = &ConvertToXmlAttribute($sFile); |
---|
75 | $sFiles .= '<File name="' . $cnv_filename . '" size="' . $iFileSize . '" />' ; |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | print $sFolders ; |
---|
80 | print '</Folders>'; # Close the "Folders" node. |
---|
81 | print $sFiles ; |
---|
82 | print '</Files>'; # Close the "Files" node. |
---|
83 | } |
---|
84 | |
---|
85 | sub CreateFolder |
---|
86 | { |
---|
87 | |
---|
88 | local($resourceType, $currentFolder) = @_; |
---|
89 | $sErrorNumber = '0' ; |
---|
90 | $sErrorMsg = '' ; |
---|
91 | |
---|
92 | if($FORM{'NewFolderName'} ne "") { |
---|
93 | $sNewFolderName = $FORM{'NewFolderName'}; |
---|
94 | $sNewFolderName =~ s/\.|\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g; |
---|
95 | # Map the virtual path to the local server path of the current folder. |
---|
96 | $sServerDir = &ServerMapFolder($resourceType, $currentFolder); |
---|
97 | if(-w $sServerDir) { |
---|
98 | $sServerDir .= $sNewFolderName; |
---|
99 | $sErrorMsg = &CreateServerFolder($sServerDir); |
---|
100 | if($sErrorMsg == 0) { |
---|
101 | $sErrorNumber = '0'; |
---|
102 | } elsif($sErrorMsg eq 'Invalid argument' || $sErrorMsg eq 'No such file or directory') { |
---|
103 | $sErrorNumber = '102'; #// Path too long. |
---|
104 | } else { |
---|
105 | $sErrorNumber = '110'; |
---|
106 | } |
---|
107 | } else { |
---|
108 | $sErrorNumber = '103'; |
---|
109 | } |
---|
110 | } else { |
---|
111 | $sErrorNumber = '102' ; |
---|
112 | } |
---|
113 | # Create the "Error" node. |
---|
114 | $cnv_errmsg = &ConvertToXmlAttribute($sErrorMsg); |
---|
115 | print '<Error number="' . $sErrorNumber . '" originalDescription="' . $cnv_errmsg . '" />'; |
---|
116 | } |
---|
117 | |
---|
118 | sub FileUpload |
---|
119 | { |
---|
120 | eval("use File::Copy;"); |
---|
121 | |
---|
122 | local($resourceType, $currentFolder) = @_; |
---|
123 | |
---|
124 | $sErrorNumber = '0' ; |
---|
125 | $sFileName = '' ; |
---|
126 | if($new_fname) { |
---|
127 | # Map the virtual path to the local server path. |
---|
128 | $sServerDir = &ServerMapFolder($resourceType,$currentFolder); |
---|
129 | |
---|
130 | # Get the uploaded file name. |
---|
131 | $sFileName = $new_fname; |
---|
132 | $sFileName =~ s/\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g; |
---|
133 | $sOriginalFileName = $sFileName; |
---|
134 | |
---|
135 | $iCounter = 0; |
---|
136 | while(1) { |
---|
137 | $sFilePath = $sServerDir . $sFileName; |
---|
138 | if(-e $sFilePath) { |
---|
139 | $iCounter++ ; |
---|
140 | ($path,$BaseName,$ext) = &RemoveExtension($sOriginalFileName); |
---|
141 | $sFileName = $BaseName . '(' . $iCounter . ').' . $ext; |
---|
142 | $sErrorNumber = '201'; |
---|
143 | } else { |
---|
144 | copy("$img_dir/$new_fname","$sFilePath"); |
---|
145 | if (defined $CHMOD_ON_UPLOAD) { |
---|
146 | if ($CHMOD_ON_UPLOAD) { |
---|
147 | umask(000); |
---|
148 | chmod($CHMOD_ON_UPLOAD,$sFilePath); |
---|
149 | } |
---|
150 | } |
---|
151 | else { |
---|
152 | umask(000); |
---|
153 | chmod(0777,$sFilePath); |
---|
154 | } |
---|
155 | unlink("$img_dir/$new_fname"); |
---|
156 | last; |
---|
157 | } |
---|
158 | } |
---|
159 | } else { |
---|
160 | $sErrorNumber = '202' ; |
---|
161 | } |
---|
162 | $sFileName =~ s/"/\\"/g; |
---|
163 | |
---|
164 | SendUploadResults($sErrorNumber, $resourceType.$currentFolder.$sFileName, $sFileName, ''); |
---|
165 | } |
---|
166 | |
---|
167 | sub SendUploadResults |
---|
168 | { |
---|
169 | |
---|
170 | local($sErrorNumber, $sFileUrl, $sFileName, $customMsg) = @_; |
---|
171 | |
---|
172 | # Minified version of the document.domain automatic fix script (#1919). |
---|
173 | # The original script can be found at _dev/domain_fix_template.js |
---|
174 | # Note: in Perl replace \ with \\ and $ with \$ |
---|
175 | print <<EOF; |
---|
176 | Content-type: text/html |
---|
177 | |
---|
178 | <script type="text/javascript"> |
---|
179 | (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;}}})(); |
---|
180 | |
---|
181 | EOF |
---|
182 | print 'window.parent.OnUploadCompleted(' . $sErrorNumber . ',"' . JS_cnv($sFileUrl) . '","' . JS_cnv($sFileName) . '","' . JS_cnv($customMsg) . '") ;'; |
---|
183 | print '</script>'; |
---|
184 | exit ; |
---|
185 | } |
---|
186 | |
---|
187 | 1; |
---|