[6779] | 1 | [//lasso
|
---|
| 2 | /*
|
---|
| 3 | * FCKeditor - The text editor for internet
|
---|
| 4 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben
|
---|
| 5 | *
|
---|
| 6 | * Licensed under the terms of the GNU Lesser General Public License:
|
---|
| 7 | * http://www.opensource.org/licenses/lgpl-license.php
|
---|
| 8 | *
|
---|
| 9 | * For further information visit:
|
---|
| 10 | * http://www.fckeditor.net/
|
---|
| 11 | *
|
---|
| 12 | * "Support Open Source software. What about a donation today?"
|
---|
| 13 | *
|
---|
| 14 | * File Name: connector.lasso
|
---|
| 15 | * This is the File Manager Connector for Lasso.
|
---|
| 16 | *
|
---|
| 17 | * File Authors:
|
---|
| 18 | * Jason Huck (jason.huck@corefive.com)
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | /*.....................................................................
|
---|
| 22 | Include global configuration. See config.lasso for details.
|
---|
| 23 | */
|
---|
| 24 | include('config.lasso');
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | /*.....................................................................
|
---|
| 28 | Translate current date/time to GMT for custom header.
|
---|
| 29 | */
|
---|
| 30 | var('headerDate') = date_localtogmt(date)->format('%a, %d %b %Y %T GMT');
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | /*.....................................................................
|
---|
| 34 | Convert query string parameters to variables and initialize output.
|
---|
| 35 | */
|
---|
| 36 | var(
|
---|
| 37 | 'Command' = action_param('Command'),
|
---|
| 38 | 'Type' = action_param('Type'),
|
---|
| 39 | 'CurrentFolder' = action_param('CurrentFolder'),
|
---|
| 40 | 'ServerPath' = action_param('ServerPath'),
|
---|
| 41 | 'NewFolderName' = action_param('NewFolderName'),
|
---|
| 42 | 'NewFile' = null,
|
---|
| 43 | 'NewFileName' = string,
|
---|
| 44 | 'OrigFilePath' = string,
|
---|
| 45 | 'NewFilePath' = string,
|
---|
| 46 | 'commandData' = string,
|
---|
| 47 | 'folders' = '\t<Folders>\n',
|
---|
| 48 | 'files' = '\t<Files>\n',
|
---|
| 49 | 'errorNumber' = integer,
|
---|
| 50 | 'responseType' = 'xml',
|
---|
| 51 | 'uploadResult' = '0'
|
---|
| 52 | );
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | /*.....................................................................
|
---|
| 56 | Calculate the path to the current folder.
|
---|
| 57 | */
|
---|
| 58 | $ServerPath == '' ? $ServerPath = $config->find('UserFilesPath');
|
---|
| 59 |
|
---|
| 60 | var('currentFolderURL' = $ServerPath
|
---|
| 61 | + $config->find('Subdirectories')->find(action_param('Type'))
|
---|
| 62 | + action_param('CurrentFolder')
|
---|
| 63 | );
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | /*.....................................................................
|
---|
| 67 | Build the appropriate response per the 'Command' parameter. Wrap the
|
---|
| 68 | entire process in an inline for file tag permissions.
|
---|
| 69 | */
|
---|
| 70 | inline($connection);
|
---|
| 71 | select($Command);
|
---|
| 72 | /*.............................................................
|
---|
| 73 | List all subdirectories in the 'Current Folder' directory.
|
---|
| 74 | */
|
---|
| 75 | case('GetFolders');
|
---|
| 76 | $commandData += '\t<Folders>\n';
|
---|
| 77 |
|
---|
| 78 | iterate(file_listdirectory($currentFolderURL), local('this'));
|
---|
| 79 | #this->endswith('/') ? $commandData += '\t\t<Folder name="' + #this->removetrailing('/')& + '" />\n';
|
---|
| 80 | /iterate;
|
---|
| 81 |
|
---|
| 82 | $commandData += '\t</Folders>\n';
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | /*.............................................................
|
---|
| 86 | List both files and folders in the 'Current Folder' directory.
|
---|
| 87 | Include the file sizes in kilobytes.
|
---|
| 88 | */
|
---|
| 89 | case('GetFoldersAndFiles');
|
---|
| 90 | iterate(file_listdirectory($currentFolderURL), local('this'));
|
---|
| 91 | if(#this->endswith('/'));
|
---|
| 92 | $folders += '\t\t<Folder name="' + #this->removetrailing('/')& + '" />\n';
|
---|
| 93 | else;
|
---|
| 94 | local('size') = file_getsize($currentFolderURL + #this) / 1024;
|
---|
| 95 | $files += '\t\t<File name="' + #this + '" size="' + #size + '" />\n';
|
---|
| 96 | /if;
|
---|
| 97 | /iterate;
|
---|
| 98 |
|
---|
| 99 | $folders += '\t</Folders>\n';
|
---|
| 100 | $files += '\t</Files>\n';
|
---|
| 101 |
|
---|
| 102 | $commandData += $folders + $files;
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | /*.............................................................
|
---|
| 106 | Create a directory 'NewFolderName' within the 'Current Folder.'
|
---|
| 107 | */
|
---|
| 108 | case('CreateFolder');
|
---|
| 109 | var('newFolder' = $currentFolderURL + $NewFolderName + '/');
|
---|
| 110 | file_create($newFolder);
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | /*.........................................................
|
---|
| 114 | Map Lasso's file error codes to FCKEditor's error codes.
|
---|
| 115 | */
|
---|
| 116 | select(file_currenterror( -errorcode));
|
---|
| 117 | case(0);
|
---|
| 118 | $errorNumber = 0;
|
---|
| 119 | case( -9983);
|
---|
| 120 | $errorNumber = 101;
|
---|
| 121 | case( -9976);
|
---|
| 122 | $errorNumber = 102;
|
---|
| 123 | case( -9977);
|
---|
| 124 | $errorNumber = 102;
|
---|
| 125 | case( -9961);
|
---|
| 126 | $errorNumber = 103;
|
---|
| 127 | case;
|
---|
| 128 | $errorNumber = 110;
|
---|
| 129 | /select;
|
---|
| 130 |
|
---|
| 131 | $commandData += '<Error number="' + $errorNumber + '" />\n';
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | /*.............................................................
|
---|
| 135 | Process an uploaded file.
|
---|
| 136 | */
|
---|
| 137 | case('FileUpload');
|
---|
| 138 | /*.........................................................
|
---|
| 139 | This is the only command that returns an HTML response.
|
---|
| 140 | */
|
---|
| 141 | $responseType = 'html';
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | /*.........................................................
|
---|
| 145 | Was a file actually uploaded?
|
---|
| 146 | */
|
---|
| 147 | file_uploads->size ? $NewFile = file_uploads->get(1) | $uploadResult = '202';
|
---|
| 148 |
|
---|
| 149 | if($uploadResult == '0');
|
---|
| 150 | /*.....................................................
|
---|
| 151 | Split the file's extension from the filename in order
|
---|
| 152 | to follow the API's naming convention for duplicate
|
---|
| 153 | files. (Test.txt, Test(1).txt, Test(2).txt, etc.)
|
---|
| 154 | */
|
---|
| 155 | $NewFileName = $NewFile->find('OrigName');
|
---|
| 156 | $OrigFilePath = $currentFolderURL + $NewFileName;
|
---|
| 157 | $NewFilePath = $OrigFilePath;
|
---|
| 158 | local('fileExtension') = '.' + $NewFile->find('OrigExtension');
|
---|
| 159 | local('shortFileName') = $NewFileName->removetrailing(#fileExtension)&;
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | /*.....................................................
|
---|
| 163 | Make sure the file extension is allowed.
|
---|
| 164 | */
|
---|
| 165 | if($config->find('DeniedExtensions')->find($Type) >> $NewFile->find('OrigExtension'));
|
---|
| 166 | $uploadResult = '202';
|
---|
| 167 | else;
|
---|
| 168 | /*.................................................
|
---|
| 169 | Rename the target path until it is unique.
|
---|
| 170 | */
|
---|
| 171 | while(file_exists($NewFilePath));
|
---|
| 172 | $NewFilePath = $currentFolderURL + #shortFileName + '(' + loop_count + ')' + #fileExtension;
|
---|
| 173 | /while;
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | /*.................................................
|
---|
| 177 | Copy the uploaded file to its final location.
|
---|
| 178 | */
|
---|
| 179 | file_copy($NewFile->find('path'), $NewFilePath);
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | /*.................................................
|
---|
| 183 | Set the error code for the response. Note whether
|
---|
| 184 | the file had to be renamed.
|
---|
| 185 | */
|
---|
| 186 | select(file_currenterror( -errorcode));
|
---|
| 187 | case(0);
|
---|
| 188 | $OrigFilePath != $NewFilePath ? $uploadResult = '201, \'' + $NewFilePath->split('/')->last + '\'';
|
---|
| 189 | case;
|
---|
| 190 | $uploadResult = '202';
|
---|
| 191 | /select;
|
---|
| 192 | /if;
|
---|
| 193 | /if;
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | /*.........................................................
|
---|
| 197 | Set the HTML response.
|
---|
| 198 | */
|
---|
| 199 | $__html_reply__ = '\
|
---|
| 200 | <script type="text/javascript">
|
---|
| 201 | window.parent.frames[\'frmUpload\'].OnUploadCompleted(' + $uploadResult + ');
|
---|
| 202 | </script>
|
---|
| 203 | ';
|
---|
| 204 | /select;
|
---|
| 205 | /inline;
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | /*.....................................................................
|
---|
| 209 | Send a custom header for xml responses.
|
---|
| 210 | */
|
---|
| 211 | if($responseType == 'xml');
|
---|
| 212 | header;
|
---|
| 213 | ]
|
---|
| 214 | HTTP/1.0 200 OK
|
---|
| 215 | Date: [$headerDate]
|
---|
| 216 | Server: Lasso Professional [lasso_version( -lassoversion)]
|
---|
| 217 | Expires: Mon, 26 Jul 1997 05:00:00 GMT
|
---|
| 218 | Last-Modified: [$headerDate]
|
---|
| 219 | Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
---|
| 220 | Pragma: no-cache
|
---|
| 221 | Keep-Alive: timeout=15, max=98
|
---|
| 222 | Connection: Keep-Alive
|
---|
| 223 | Content-Type: text/xml; charset=utf-8
|
---|
| 224 | [//lasso
|
---|
| 225 | /header;
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | /*.................................................................
|
---|
| 229 | Set the content type encoding for Lasso.
|
---|
| 230 | */
|
---|
| 231 | content_type('text/xml; charset=utf-8');
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 | /*.................................................................
|
---|
| 235 | Wrap the response as XML and output.
|
---|
| 236 | */
|
---|
| 237 | $__html_reply__ = '\
|
---|
| 238 | <?xml version="1.0" encoding="utf-8" ?>
|
---|
| 239 | <Connector command="' + $Command + '" resourceType="' + $Type + '">
|
---|
| 240 | <CurrentFolder path="' + $CurrentFolder + '" url="' + $currentFolderURL + '" />
|
---|
| 241 | ' + $commandData + '
|
---|
| 242 | </Connector>
|
---|
| 243 | ';
|
---|
| 244 | /if;
|
---|
| 245 | ]
|
---|