connector.lasso
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:11k
源码类别:

OA系统

开发平台:

C#

  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.     Include global configuration. See config.lasso for details.                                                                           
  22.     */                                                                          
  23. include('config.lasso');
  24.     /*.....................................................................     
  25.     Translate current date/time to GMT for custom header.                                                                          
  26.     */                                                                          
  27. var('headerDate') = date_localtogmt(date)->format('%a, %d %b %Y %T GMT');
  28.     /*.....................................................................     
  29.     Convert query string parameters to variables and initialize output.                                                                           
  30.     */                                                                          
  31. var(
  32. 'Command' = action_param('Command'),
  33. 'Type' = action_param('Type'),
  34. 'CurrentFolder' = action_param('CurrentFolder'),
  35. 'ServerPath' = action_param('ServerPath'),
  36. 'NewFolderName' = action_param('NewFolderName'),
  37. 'NewFile' = null,
  38. 'NewFileName' = string,
  39. 'OrigFilePath' = string,
  40. 'NewFilePath' = string,
  41. 'commandData' = string,
  42. 'folders' = 't<Folders>n',
  43. 'files' = 't<Files>n',
  44. 'errorNumber' = integer,
  45. 'responseType' = 'xml',
  46. 'uploadResult' = '0'
  47. );
  48.     /*.....................................................................     
  49.     Calculate the path to the current folder.                                                                           
  50.     */                                                                          
  51. $ServerPath == '' ? $ServerPath = $config->find('UserFilesPath');
  52. var('currentFolderURL' = $ServerPath 
  53. + $config->find('Subdirectories')->find(action_param('Type'))
  54. + action_param('CurrentFolder')
  55. );
  56.     /*.....................................................................     
  57.     Build the appropriate response per the 'Command' parameter. Wrap the
  58.     entire process in an inline for file tag permissions.                                                                         
  59.     */                                                                          
  60. inline($connection);
  61. select($Command);
  62.             /*.............................................................     
  63.             List all subdirectories in the 'Current Folder' directory.                                                                   
  64.             */                                                                  
  65. case('GetFolders');
  66. $commandData += 't<Folders>n';
  67. iterate(file_listdirectory($currentFolderURL), local('this'));
  68. #this->endswith('/') ? $commandData += 'tt<Folder name="' + #this->removetrailing('/')& + '" />n';
  69. /iterate;
  70. $commandData += 't</Folders>n';
  71.             /*.............................................................     
  72.             List both files and folders in the 'Current Folder' directory.
  73.             Include the file sizes in kilobytes.                                                                   
  74.             */                                                                  
  75. case('GetFoldersAndFiles');
  76. iterate(file_listdirectory($currentFolderURL), local('this'));
  77. if(#this->endswith('/'));
  78. $folders += 'tt<Folder name="' + #this->removetrailing('/')& + '" />n';
  79. else;
  80. local('size') = file_getsize($currentFolderURL + #this) / 1024;
  81. $files += 'tt<File name="' + #this + '" size="' + #size + '" />n';
  82. /if;
  83. /iterate;
  84. $folders += 't</Folders>n';
  85. $files += 't</Files>n';
  86. $commandData += $folders + $files;
  87.             /*.............................................................     
  88.             Create a directory 'NewFolderName' within the 'Current Folder.'                                                                 
  89.             */                                                                  
  90. case('CreateFolder');
  91. var('newFolder' = $currentFolderURL + $NewFolderName + '/');
  92. file_create($newFolder);
  93.                 /*.........................................................     
  94.                 Map Lasso's file error codes to FCKEditor's error codes.                                                              
  95.                 */                                                              
  96. select(file_currenterror( -errorcode));
  97. case(0);
  98. $errorNumber = 0;
  99. case( -9983);
  100. $errorNumber = 101;
  101. case( -9976);
  102. $errorNumber = 102;
  103. case( -9977);
  104. $errorNumber = 102;
  105. case( -9961);
  106. $errorNumber = 103;
  107. case;
  108. $errorNumber = 110;
  109. /select;
  110. $commandData += '<Error number="' + $errorNumber + '" />n';
  111.             /*.............................................................     
  112.             Process an uploaded file.                                                                  
  113.             */                                                                  
  114. case('FileUpload');
  115.                 /*.........................................................     
  116.                 This is the only command that returns an HTML response.                                                              
  117.                 */                                                              
  118. $responseType = 'html';
  119.                 /*.........................................................     
  120.                 Was a file actually uploaded?                                                              
  121.                 */                                                              
  122. file_uploads->size ? $NewFile = file_uploads->get(1) | $uploadResult = '202';
  123. if($uploadResult == '0');
  124.                     /*.....................................................     
  125.                     Split the file's extension from the filename in order
  126.                     to follow the API's naming convention for duplicate
  127.                     files. (Test.txt, Test(1).txt, Test(2).txt, etc.)                                                          
  128.                     */                                                          
  129. $NewFileName = $NewFile->find('OrigName');
  130. $OrigFilePath = $currentFolderURL + $NewFileName;
  131. $NewFilePath = $OrigFilePath;
  132. local('fileExtension') = '.' + $NewFile->find('OrigExtension');
  133. local('shortFileName') = $NewFileName->removetrailing(#fileExtension)&;
  134.                     /*.....................................................     
  135.                     Make sure the file extension is allowed.                                                          
  136.                     */                                                          
  137. if($config->find('DeniedExtensions')->find($Type) >> $NewFile->find('OrigExtension'));
  138. $uploadResult = '202';
  139. else;
  140.                         /*.................................................     
  141.                         Rename the target path until it is unique.                                                    
  142.                         */                                                      
  143. while(file_exists($NewFilePath));
  144. $NewFilePath = $currentFolderURL + #shortFileName + '(' + loop_count + ')' + #fileExtension;
  145. /while;
  146.                         /*.................................................     
  147.                         Copy the uploaded file to its final location.                                                     
  148.                         */                                                      
  149. file_copy($NewFile->find('path'), $NewFilePath);
  150.                         /*.................................................     
  151.                         Set the error code for the response. Note whether
  152.                         the file had to be renamed.                                                      
  153.                         */                                                      
  154. select(file_currenterror( -errorcode));
  155. case(0);
  156. $OrigFilePath != $NewFilePath ? $uploadResult = '201, '' + $NewFilePath->split('/')->last + ''';
  157. case;
  158. $uploadResult = '202';
  159. /select;
  160. /if;
  161. /if;
  162.                 /*.........................................................     
  163.                 Set the HTML response.                                                               
  164.                 */                                                              
  165. $__html_reply__ = '
  166. <script type="text/javascript">
  167. window.parent.frames['frmUpload'].OnUploadCompleted(' + $uploadResult + ');
  168. </script>
  169. ';
  170. /select;
  171. /inline;
  172.     /*.....................................................................     
  173.     Send a custom header for xml responses.                                                                          
  174.     */                                                                          
  175. if($responseType == 'xml');
  176. header;
  177. ]
  178. HTTP/1.0 200 OK
  179. Date: [$headerDate]
  180. Server: Lasso Professional [lasso_version( -lassoversion)]
  181. Expires: Mon, 26 Jul 1997 05:00:00 GMT
  182. Last-Modified: [$headerDate]
  183. Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  184. Pragma: no-cache
  185. Keep-Alive: timeout=15, max=98
  186. Connection: Keep-Alive
  187. Content-Type: text/xml; charset=utf-8
  188. [//lasso
  189. /header;
  190.         /*.................................................................     
  191.         Set the content type encoding for Lasso.                                                                      
  192.         */                                                                      
  193. content_type('text/xml; charset=utf-8');
  194.         /*.................................................................     
  195.         Wrap the response as XML and output.                                                                      
  196.         */                                                                      
  197. $__html_reply__ = '
  198. <?xml version="1.0" encoding="utf-8" ?>
  199. <Connector command="' + $Command + '" resourceType="' + $Type + '">
  200. <CurrentFolder path="' + $CurrentFolder + '" url="' + $currentFolderURL + '" />
  201. ' + $commandData + '
  202. </Connector>
  203. ';
  204. /if;
  205. ]