connector.lasso
上传用户:ah_jiwei
上传日期:2022-07-24
资源大小:54044k
文件大小:9k
源码类别:

数据库编程

开发平台:

Visual C++

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