PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/source/Plug-in/fck/editor/filemanager/connectors/lasso/upload.lasso

http://prosporous.googlecode.com/
Unknown | 157 lines | 136 code | 21 blank | 0 comment | 0 complexity | cdeefea93db4e3980357eb5029a7d996 MD5 | raw file
  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 Uploader" for Lasso.
 23 */
 24
 25    /*.....................................................................
 26    Include global configuration. See config.lasso for details.
 27    */
 28	include('config.lasso');
 29
 30
 31    /*.....................................................................
 32    Convert query string parameters to variables and initialize output.
 33    */
 34	var(
 35		'Type'			=	action_param('Type'),
 36		'CurrentFolder'	=	action_param('CurrentFolder'),
 37		'ServerPath'	=	action_param('ServerPath'),
 38		'NewFile'		=	null,
 39		'NewFileName'	=	string,
 40		'OrigFilePath'	=	string,
 41		'NewFilePath'	=	string,
 42		'errorNumber'	=	0,
 43		'customMsg'		=	''
 44	);
 45
 46	$Type == '' ? $Type = 'File';
 47
 48
 49    /*.....................................................................
 50    Calculate the path to the current folder.
 51    */
 52	$ServerPath == '' ? $ServerPath = $config->find('UserFilesPath');
 53
 54	var('currentFolderURL' = $ServerPath
 55		+ $config->find('Subdirectories')->find(action_param('Type'))
 56		+ action_param('CurrentFolder')
 57	);
 58
 59
 60	/*.....................................................................
 61	Custom tag sets the HTML response.
 62	*/
 63
 64	define_tag(
 65		'sendresults',
 66		-namespace='fck_',
 67		-priority='replace',
 68		-required='errorNumber',
 69		-type='integer',
 70		-optional='fileUrl',
 71		-type='string',
 72		-optional='fileName',
 73		-type='string',
 74		-optional='customMsg',
 75		-type='string',
 76		-description='Sets the HTML response for the FCKEditor Quick Upload feature.'
 77	);
 78		$__html_reply__ = '\
 79<script type="text/javascript">
 80	window.parent.OnUploadCompleted(' + #errorNumber + ',"'
 81		+ string_replace(#fileUrl, -find='"', -replace='\\"') + '","'
 82		+ string_replace(#fileName, -find='"', -replace='\\"') + '","'
 83		+ string_replace(#customMsg, -find='"', -replace='\\"') + '");
 84</script>
 85		';
 86	/define_tag;
 87
 88
 89	if($config->find('Enabled'));
 90		/*.................................................................
 91		Process an uploaded file.
 92		*/
 93		inline($connection);
 94			/*.............................................................
 95			Was a file actually uploaded?
 96			*/
 97			file_uploads->size ? $NewFile = file_uploads->get(1) | $errorNumber = 202;
 98
 99			if($errorNumber == 0);
100				/*.........................................................
101				Split the file's extension from the filename in order
102				to follow the API's naming convention for duplicate
103				files. (Test.txt, Test(1).txt, Test(2).txt, etc.)
104				*/
105				$NewFileName = $NewFile->find('OrigName');
106				$OrigFilePath = $currentFolderURL + $NewFileName;
107				$NewFilePath = $OrigFilePath;
108				local('fileExtension') = '.' + $NewFile->find('OrigExtension');
109				local('shortFileName') = $NewFileName->removetrailing(#fileExtension)&;
110
111
112				/*.........................................................
113				Make sure the file extension is allowed.
114				*/
115
116				if($config->find('DeniedExtensions')->find($Type) >> $NewFile->find('OrigExtension'));
117					$errorNumber = 202;
118				else;
119					/*.....................................................
120					Rename the target path until it is unique.
121					*/
122					while(file_exists($NewFilePath));
123						$NewFileName = #shortFileName + '(' + loop_count + ')' + #fileExtension;
124						$NewFilePath = $currentFolderURL + $NewFileName;
125					/while;
126
127
128					/*.....................................................
129					Copy the uploaded file to its final location.
130					*/
131					file_copy($NewFile->find('path'), $NewFilePath);
132
133
134					/*.....................................................
135					Set the error code for the response.
136					*/
137					select(file_currenterror( -errorcode));
138						case(0);
139							$OrigFilePath != $NewFilePath ? $errorNumber = 201;
140						case;
141							$errorNumber = 202;
142					/select;
143				/if;
144			/if;
145		/inline;
146	else;
147		$errorNumber = 1;
148		$customMsg = 'This file uploader is disabled. Please check the "editor/filemanager/upload/lasso/config.lasso" file.';
149	/if;
150
151	fck_sendresults(
152		-errorNumber=$errorNumber,
153		-fileUrl=$NewFilePath,
154		-fileName=$NewFileName,
155		-customMsg=$customMsg
156	);
157]