1 | #####
|
---|
2 | # FCKeditor - The text editor for internet
|
---|
3 | # Copyright (C) 2003-2006 Frederico Caldeira Knabben
|
---|
4 | #
|
---|
5 | # Licensed under the terms of the GNU Lesser General Public License:
|
---|
6 | # http://www.opensource.org/licenses/lgpl-license.php
|
---|
7 | #
|
---|
8 | # For further information visit:
|
---|
9 | # http://www.fckeditor.net/
|
---|
10 | #
|
---|
11 | # "Support Open Source software. What about a donation today?"
|
---|
12 | #
|
---|
13 | # File Name: commands.pl
|
---|
14 | # This is the File Manager Connector for Perl.
|
---|
15 | #
|
---|
16 | # File Authors:
|
---|
17 | # Takashi Yamaguchi (jack@omakase.net)
|
---|
18 | #####
|
---|
19 |
|
---|
20 | sub GetFolders
|
---|
21 | {
|
---|
22 |
|
---|
23 | local($resourceType, $currentFolder) = @_;
|
---|
24 |
|
---|
25 | # Map the virtual path to the local server path.
|
---|
26 | $sServerDir = &ServerMapFolder($resourceType, $currentFolder);
|
---|
27 | print "<Folders>"; # Open the "Folders" node.
|
---|
28 |
|
---|
29 | opendir(DIR,"$sServerDir");
|
---|
30 | @files = grep(!/^\.\.?$/,readdir(DIR));
|
---|
31 | closedir(DIR);
|
---|
32 |
|
---|
33 | foreach $sFile (@files) {
|
---|
34 | if($sFile != '.' && $sFile != '..' && (-d "$sServerDir$sFile")) {
|
---|
35 | $cnv_filename = &ConvertToXmlAttribute($sFile);
|
---|
36 | print '<Folder name="' . $cnv_filename . '" />';
|
---|
37 | }
|
---|
38 | }
|
---|
39 | print "</Folders>"; # Close the "Folders" node.
|
---|
40 | }
|
---|
41 |
|
---|
42 | sub GetFoldersAndFiles
|
---|
43 | {
|
---|
44 |
|
---|
45 | local($resourceType, $currentFolder) = @_;
|
---|
46 | # Map the virtual path to the local server path.
|
---|
47 | $sServerDir = &ServerMapFolder($resourceType,$currentFolder);
|
---|
48 |
|
---|
49 | # Initialize the output buffers for "Folders" and "Files".
|
---|
50 | $sFolders = '<Folders>';
|
---|
51 | $sFiles = '<Files>';
|
---|
52 |
|
---|
53 | opendir(DIR,"$sServerDir");
|
---|
54 | @files = grep(!/^\.\.?$/,readdir(DIR));
|
---|
55 | closedir(DIR);
|
---|
56 |
|
---|
57 | foreach $sFile (@files) {
|
---|
58 | if($sFile ne '.' && $sFile ne '..') {
|
---|
59 | if(-d "$sServerDir$sFile") {
|
---|
60 | $cnv_filename = &ConvertToXmlAttribute($sFile);
|
---|
61 | $sFolders .= '<Folder name="' . $cnv_filename . '" />' ;
|
---|
62 | } else {
|
---|
63 | ($iFileSize,$refdate,$filedate,$fileperm) = (stat("$sServerDir$sFile"))[7,8,9,2];
|
---|
64 | if($iFileSize > 0) {
|
---|
65 | $iFileSize = int($iFileSize / 1024);
|
---|
66 | if($iFileSize < 1) {
|
---|
67 | $iFileSize = 1;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | $cnv_filename = &ConvertToXmlAttribute($sFile);
|
---|
71 | $sFiles .= '<File name="' . $cnv_filename . '" size="' . $iFileSize . '" />' ;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | print $sFolders ;
|
---|
76 | print '</Folders>'; # Close the "Folders" node.
|
---|
77 | print $sFiles ;
|
---|
78 | print '</Files>'; # Close the "Files" node.
|
---|
79 | }
|
---|
80 |
|
---|
81 | sub CreateFolder
|
---|
82 | {
|
---|
83 |
|
---|
84 | local($resourceType, $currentFolder) = @_;
|
---|
85 | $sErrorNumber = '0' ;
|
---|
86 | $sErrorMsg = '' ;
|
---|
87 |
|
---|
88 | if($FORM{'NewFolderName'} ne "") {
|
---|
89 | $sNewFolderName = $FORM{'NewFolderName'};
|
---|
90 | # Map the virtual path to the local server path of the current folder.
|
---|
91 | $sServerDir = &ServerMapFolder($resourceType, $currentFolder);
|
---|
92 | if(-w $sServerDir) {
|
---|
93 | $sServerDir .= $sNewFolderName;
|
---|
94 | $sErrorMsg = &CreateServerFolder($sServerDir);
|
---|
95 | if($sErrorMsg == 0) {
|
---|
96 | $sErrorNumber = '0';
|
---|
97 | } elsif($sErrorMsg eq 'Invalid argument' || $sErrorMsg eq 'No such file or directory') {
|
---|
98 | $sErrorNumber = '102'; #// Path too long.
|
---|
99 | } else {
|
---|
100 | $sErrorNumber = '110';
|
---|
101 | }
|
---|
102 | } else {
|
---|
103 | $sErrorNumber = '103';
|
---|
104 | }
|
---|
105 | } else {
|
---|
106 | $sErrorNumber = '102' ;
|
---|
107 | }
|
---|
108 | # Create the "Error" node.
|
---|
109 | $cnv_errmsg = &ConvertToXmlAttribute($sErrorMsg);
|
---|
110 | print '<Error number="' . $sErrorNumber . '" originalDescription="' . $cnv_errmsg . '" />';
|
---|
111 | }
|
---|
112 |
|
---|
113 | sub FileUpload
|
---|
114 | {
|
---|
115 | eval("use File::Copy;");
|
---|
116 |
|
---|
117 | local($resourceType, $currentFolder) = @_;
|
---|
118 |
|
---|
119 | $sErrorNumber = '0' ;
|
---|
120 | $sFileName = '' ;
|
---|
121 | if($new_fname) {
|
---|
122 | # Map the virtual path to the local server path.
|
---|
123 | $sServerDir = &ServerMapFolder($resourceType,$currentFolder);
|
---|
124 |
|
---|
125 | # Get the uploaded file name.
|
---|
126 | $sFileName = $new_fname;
|
---|
127 | $sOriginalFileName = $sFileName;
|
---|
128 |
|
---|
129 | $iCounter = 0;
|
---|
130 | while(1) {
|
---|
131 | $sFilePath = $sServerDir . $sFileName;
|
---|
132 | if(-e $sFilePath) {
|
---|
133 | $iCounter++ ;
|
---|
134 | ($path,$BaseName,$ext) = &RemoveExtension($sOriginalFileName);
|
---|
135 | $sFileName = $BaseName . '(' . $iCounter . ').' . $ext;
|
---|
136 | $sErrorNumber = '201';
|
---|
137 | } else {
|
---|
138 | copy("$img_dir/$new_fname","$sFilePath");
|
---|
139 | chmod(0777,$sFilePath);
|
---|
140 | unlink("$img_dir/$new_fname");
|
---|
141 | last;
|
---|
142 | }
|
---|
143 | }
|
---|
144 | } else {
|
---|
145 | $sErrorNumber = '202' ;
|
---|
146 | }
|
---|
147 | $sFileName =~ s/"/\\"/g;
|
---|
148 | print "Content-type: text/html\n\n";
|
---|
149 | print '<script type="text/javascript">';
|
---|
150 | print 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . $sFileName . '") ;';
|
---|
151 | print '</script>';
|
---|
152 | exit ;
|
---|
153 | }
|
---|
154 | 1;
|
---|