--- /dev/null
+[//lasso\r
+/*\r
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ * Copyright (C) 2003-2008 Frederico Caldeira Knabben\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ * - GNU General Public License Version 2 or later (the "GPL")\r
+ * http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ * http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ * - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ * http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ * This is the File Manager Connector for Lasso.\r
+ */\r
+\r
+ /*.....................................................................\r
+ Include global configuration. See config.lasso for details.\r
+ */\r
+ include('config.lasso');\r
+\r
+\r
+ /*.....................................................................\r
+ Translate current date/time to GMT for custom header.\r
+ */\r
+ var('headerDate') = date_localtogmt(date)->format('%a, %d %b %Y %T GMT');\r
+\r
+\r
+ /*.....................................................................\r
+ Convert query string parameters to variables and initialize output.\r
+ */\r
+ var(\r
+ 'Command' = action_param('Command'),\r
+ 'Type' = action_param('Type'),\r
+ 'CurrentFolder' = action_param('CurrentFolder'),\r
+ 'ServerPath' = action_param('ServerPath'),\r
+ 'NewFolderName' = action_param('NewFolderName'),\r
+ 'NewFile' = null,\r
+ 'NewFileName' = string,\r
+ 'OrigFilePath' = string,\r
+ 'NewFilePath' = string,\r
+ 'commandData' = string,\r
+ 'folders' = '\t<Folders>\n',\r
+ 'files' = '\t<Files>\n',\r
+ 'errorNumber' = integer,\r
+ 'responseType' = 'xml',\r
+ 'uploadResult' = '0'\r
+ );\r
+\r
+ /*.....................................................................\r
+ Custom tag sets the HTML response.\r
+ */\r
+\r
+ define_tag(\r
+ 'htmlreply',\r
+ -namespace='fck_',\r
+ -priority='replace',\r
+ -required='uploadResult',\r
+ -optional='NewFilePath',\r
+ -type='string',\r
+ -description='Sets the HTML response for the FCKEditor File Upload feature.'\r
+ );\r
+ $__html_reply__ = '\\r
+<script type="text/javascript">\r
+(function()\r
+{\r
+ var d = document.domain ;\r
+\r
+ while ( true )\r
+ {\r
+ // Test if we can access a parent property.\r
+ try\r
+ {\r
+ var test = window.top.opener.document.domain ;\r
+ break ;\r
+ }\r
+ catch( e ) {}\r
+\r
+ // Remove a domain part: www.mytest.example.com => mytest.example.com => example.com ...\r
+ d = d.replace( /.*?(?:\\.|$)/, "" ) ;\r
+\r
+ if ( d.length == 0 )\r
+ break ; // It was not able to detect the domain.\r
+\r
+ try\r
+ {\r
+ document.domain = d ;\r
+ }\r
+ catch (e)\r
+ {\r
+ break ;\r
+ }\r
+ }\r
+})() ;\r
+';\r
+ if($uploadResult == '0' || $uploadResult == '201');\r
+ $__html_reply__ = $__html_reply__ + '\\r
+ window.parent.OnUploadCompleted(' + $uploadResult + ',\'' + $NewFilePath + '\',\'' + $NewFilePath->split('/')->last + '\');\r
+</script>\r
+ ';\r
+ else;\r
+ $__html_reply__ = $__html_reply__ + '\\r
+ window.parent.OnUploadCompleted(' + $uploadResult + ');\r
+</script>\r
+ ';\r
+ /if;\r
+ /define_tag;\r
+\r
+\r
+ /*.....................................................................\r
+ Calculate the path to the current folder.\r
+ */\r
+ $ServerPath == '' ? $ServerPath = $config->find('UserFilesPath');\r
+\r
+ var('currentFolderURL' = $ServerPath\r
+ + $config->find('Subdirectories')->find(action_param('Type'))\r
+ + $CurrentFolder\r
+ );\r
+\r
+ if($CurrentFolder->(Find: '..') || $CurrentFolder->(Find: '\\'));\r
+ if($Command == 'FileUpload');\r
+ $responseType = 'html';\r
+ $uploadResult = '102';\r
+ fck_htmlreply(\r
+ -uploadResult=$uploadResult\r
+ );\r
+ else;\r
+ $errorNumber = 102;\r
+ $commandData += '<Error number="' + $errorNumber + '" />\n';\r
+ /if;\r
+ else;\r
+\r
+ /*.....................................................................\r
+ Build the appropriate response per the 'Command' parameter. Wrap the\r
+ entire process in an inline for file tag permissions.\r
+ */\r
+ inline($connection);\r
+ select($Command);\r
+ /*.............................................................\r
+ List all subdirectories in the 'Current Folder' directory.\r
+ */\r
+ case('GetFolders');\r
+ $commandData += '\t<Folders>\n';\r
+\r
+ iterate(file_listdirectory($currentFolderURL), local('this'));\r
+ #this->endswith('/') ? $commandData += '\t\t<Folder name="' + #this->removetrailing('/')& + '" />\n';\r
+ /iterate;\r
+\r
+ $commandData += '\t</Folders>\n';\r
+\r
+\r
+ /*.............................................................\r
+ List both files and folders in the 'Current Folder' directory.\r
+ Include the file sizes in kilobytes.\r
+ */\r
+ case('GetFoldersAndFiles');\r
+ iterate(file_listdirectory($currentFolderURL), local('this'));\r
+ if(#this->endswith('/'));\r
+ $folders += '\t\t<Folder name="' + #this->removetrailing('/')& + '" />\n';\r
+ else;\r
+ local('size') = file_getsize($currentFolderURL + #this) / 1024;\r
+ $files += '\t\t<File name="' + #this + '" size="' + #size + '" />\n';\r
+ /if;\r
+ /iterate;\r
+\r
+ $folders += '\t</Folders>\n';\r
+ $files += '\t</Files>\n';\r
+\r
+ $commandData += $folders + $files;\r
+\r
+\r
+ /*.............................................................\r
+ Create a directory 'NewFolderName' within the 'Current Folder.'\r
+ */\r
+ case('CreateFolder');\r
+ $NewFolderName = (String_ReplaceRegExp: $NewFolderName, -find='\\.|\\\\|\\/|\\||\\:|\\?|\\*|"|<|>', -replace='_');\r
+ var('newFolder' = $currentFolderURL + $NewFolderName + '/');\r
+ file_create($newFolder);\r
+\r
+\r
+ /*.........................................................\r
+ Map Lasso's file error codes to FCKEditor's error codes.\r
+ */\r
+ select(file_currenterror( -errorcode));\r
+ case(0);\r
+ $errorNumber = 0;\r
+ case( -9983);\r
+ $errorNumber = 101;\r
+ case( -9976);\r
+ $errorNumber = 102;\r
+ case( -9977);\r
+ $errorNumber = 102;\r
+ case( -9961);\r
+ $errorNumber = 103;\r
+ case;\r
+ $errorNumber = 110;\r
+ /select;\r
+\r
+ $commandData += '<Error number="' + $errorNumber + '" />\n';\r
+\r
+\r
+ /*.............................................................\r
+ Process an uploaded file.\r
+ */\r
+ case('FileUpload');\r
+ /*.........................................................\r
+ This is the only command that returns an HTML response.\r
+ */\r
+ $responseType = 'html';\r
+\r
+\r
+ /*.........................................................\r
+ Was a file actually uploaded?\r
+ */\r
+ if(file_uploads->size);\r
+ $NewFile = file_uploads->get(1);\r
+ else;\r
+ $uploadResult = '202';\r
+ /if;\r
+\r
+ if($uploadResult == '0');\r
+ /*.....................................................\r
+ Split the file's extension from the filename in order\r
+ to follow the API's naming convention for duplicate\r
+ files. (Test.txt, Test(1).txt, Test(2).txt, etc.)\r
+ */\r
+ $NewFileName = $NewFile->find('OrigName');\r
+ $NewFileName = (String_ReplaceRegExp: $NewFileName, -find='\\\\|\\/|\\||\\:|\\?|\\*|"|<|>', -replace='_');\r
+ $OrigFilePath = $currentFolderURL + $NewFileName;\r
+ $NewFilePath = $OrigFilePath;\r
+ local('fileExtension') = '.' + $NewFile->find('OrigExtension');\r
+ #fileExtension = (String_ReplaceRegExp: #fileExtension, -find='\\\\|\\/|\\||\\:|\\?|\\*|"|<|>', -replace='_');\r
+ local('shortFileName') = $NewFileName->removetrailing(#fileExtension)&;\r
+\r
+\r
+ /*.....................................................\r
+ Make sure the file extension is allowed.\r
+ */\r
+ if($config->find('DeniedExtensions')->find($Type) >> $NewFile->find('OrigExtension'));\r
+ $uploadResult = '202';\r
+ else;\r
+ /*.................................................\r
+ Rename the target path until it is unique.\r
+ */\r
+ while(file_exists($NewFilePath));\r
+ $NewFilePath = $currentFolderURL + #shortFileName + '(' + loop_count + ')' + #fileExtension;\r
+ /while;\r
+\r
+\r
+ /*.................................................\r
+ Copy the uploaded file to its final location.\r
+ */\r
+ file_copy($NewFile->find('path'), $NewFilePath);\r
+\r
+\r
+ /*.................................................\r
+ Set the error code for the response. Note whether\r
+ the file had to be renamed.\r
+ */\r
+ select(file_currenterror( -errorcode));\r
+ case(0);\r
+ $OrigFilePath != $NewFilePath ? $uploadResult = 201;\r
+ case;\r
+ $uploadResult = file_currenterror( -errorcode);\r
+ /select;\r
+ /if;\r
+ /if;\r
+ fck_htmlreply(\r
+ -uploadResult=$uploadResult,\r
+ -NewFilePath=$NewFilePath\r
+ );\r
+ /select;\r
+ /inline;\r
+ /if;\r
+\r
+ /*.....................................................................\r
+ Send a custom header for xml responses.\r
+ */\r
+ if($responseType == 'xml');\r
+ header;\r
+]\r
+HTTP/1.0 200 OK\r
+Date: [$headerDate]\r
+Server: Lasso Professional [lasso_version( -lassoversion)]\r
+Expires: Mon, 26 Jul 1997 05:00:00 GMT\r
+Last-Modified: [$headerDate]\r
+Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r
+Pragma: no-cache\r
+Keep-Alive: timeout=15, max=98\r
+Connection: Keep-Alive\r
+Content-Type: text/xml; charset=utf-8\r
+[//lasso\r
+/header;\r
+\r
+ /*\r
+ Set the content type encoding for Lasso.\r
+ */\r
+ content_type('text/xml; charset=utf-8');\r
+\r
+ /*\r
+ Wrap the response as XML and output.\r
+ */\r
+ $__html_reply__ = '\\r
+<?xml version="1.0" encoding="utf-8" ?>\r
+<Connector command="' + $Command + '" resourceType="' + $Type + '">';\r
+\r
+ if($errorNumber != '102');\r
+ $__html_reply__ += '<CurrentFolder path="' + $CurrentFolder + '" url="' + $currentFolderURL + '" />';\r
+ /if;\r
+\r
+ $__html_reply__ += $commandData + '\r
+</Connector>';\r
+ /if;\r
+]\r