Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/commands.asp
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/commands.asp	(revision 289)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/commands.asp	(revision 290)
@@ -33,4 +33,9 @@
 	Dim oFSO, oCurrentFolder, oFolders, oFolder
 	Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
+	if not (oFSO.FolderExists( sServerDir ) ) then
+		Set oFSO = Nothing
+		SendError 102, currentFolder
+	end if
+
 	Set oCurrentFolder = oFSO.GetFolder( sServerDir )
 	Set oFolders = oCurrentFolder.SubFolders
@@ -53,4 +58,9 @@
 	Dim oFSO, oCurrentFolder, oFolders, oFolder, oFiles, oFile
 	Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
+	if not (oFSO.FolderExists( sServerDir ) ) then
+		Set oFSO = Nothing
+		SendError 102, currentFolder
+	end if
+
 	Set oCurrentFolder = oFSO.GetFolder( sServerDir )
 	Set oFolders	= oCurrentFolder.SubFolders
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/connector.asp
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/connector.asp	(revision 289)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/connector.asp	(revision 290)
@@ -45,27 +45,19 @@
 	' Get the main request information.
 	sCommand = Request.QueryString("Command")
+
+	sResourceType = Request.QueryString("Type")
+	If ( sResourceType = "" ) Then sResourceType = "File"
+
+	sCurrentFolder = GetCurrentFolder()
+
+	' Check if it is an allowed command 
 	if ( Not IsAllowedCommand( sCommand ) ) then
 		SendError 1, "The """ & sCommand & """ command isn't allowed"
 	end if
 
-	sResourceType = Request.QueryString("Type")
-	If ( sResourceType = "" ) Then sResourceType = "File"
-
-	sCurrentFolder = Request.QueryString("CurrentFolder")
-	If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"
-
-	' Check if it is an allower resource type.
+	' Check if it is an allowed resource type.
 	if ( Not IsAllowedType( sResourceType ) ) Then 
 		SendError 1, "The """ & sResourceType & """ resource type isn't allowed"
 	end if
-
-	' Check the current folder syntax (must begin and start with a slash).
-	If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
-	If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder
-
-	' Check for invalid folder paths (..)
-	If ( InStr( 1, sCurrentFolder, ".." ) <> 0 OR InStr( 1, sResourceType, ".." ) <> 0 ) Then
-		SendError 102, ""
-	End If
 
 	' File Upload doesn't have to Return XML, so it must be intercepted before anything.
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/io.asp
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/io.asp	(revision 289)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/io.asp	(revision 290)
@@ -140,4 +140,21 @@
 End Function
 
+function GetCurrentFolder()
+{
+	dim sCurrentFolder
+	sCurrentFolder = Request.QueryString("CurrentFolder")
+	If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"
+
+	' Check the current folder syntax (must begin and start with a slash).
+	If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
+	If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder
+
+	' Check for invalid folder paths (..)
+	If ( InStr( 1, sCurrentFolder, ".." ) <> 0 ) Then
+		SendError 102, ""
+	End If
+
+	GetCurrentFolder = sCurrentFolder
+end function
 
 ' This is the function that sends the results of the uploading process.
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/upload.asp
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/upload.asp	(revision 289)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/asp/upload.asp	(revision 290)
@@ -41,28 +41,20 @@
 
 	sCommand = "FileUpload"
-	if ( Not IsAllowedCommand( sCommand ) ) then
-		SendError 1, "The """ & sCommand & """ command isn't allowed"
-	end if
 
 	sResourceType = Request.QueryString("Type")
 	If ( sResourceType = "" ) Then sResourceType = "File"
 
-	sCurrentFolder = Request.QueryString("CurrentFolder")
-	If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"
+	sCurrentFolder = GetCurrentFolder()
 
-	' Check if it is an allower resource type.
+	' Is Upload enabled?
+	if ( Not IsAllowedCommand( sCommand ) ) then
+		SendUploadResults "1", "", "", "The """ & sCommand & """ command isn't allowed"
+	end if
+
+	' Check if it is an allowed resource type.
 	if ( Not IsAllowedType( sResourceType ) ) Then
 		SendUploadResults "1", "", "", "The " & sResourceType & " resource type isn't allowed"
 	end if
 
-	' Check the current folder syntax (must begin and start with a slash).
-	If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
-	If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder
-
-	' Check for invalid folder paths (..)
-	If ( InStr( 1, sCurrentFolder, ".." ) <> 0 OR InStr( 1, sResourceType, ".." ) <> 0 ) Then
-		SendUploadResults "102", "", "", "Invalid path"
-	End If
-
 	FileUpload sResourceType, sCurrentFolder
 
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/basexml.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/basexml.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/basexml.php	(revision 290)
@@ -0,0 +1,75 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * These functions define the base of the XML response sent by the PHP
+ * connector.
+ */
+
+function SetXmlHeaders()
+{
+	ob_end_clean() ;
+
+	// Prevent the browser from caching the result.
+	// Date in the past
+	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT') ;
+	// always modified
+	header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT') ;
+	// HTTP/1.1
+	header('Cache-Control: no-store, no-cache, must-revalidate') ;
+	header('Cache-Control: post-check=0, pre-check=0', false) ;
+	// HTTP/1.0
+	header('Pragma: no-cache') ;
+
+	// Set the response format.
+	header( 'Content-Type:text/xml; charset=utf-8' ) ;
+}
+
+function CreateXmlHeader( $command, $resourceType, $currentFolder )
+{
+	SetXmlHeaders() ;
+
+	// Create the XML document header.
+	echo '<?xml version="1.0" encoding="utf-8" ?>' ;
+
+	// Create the main "Connector" node.
+	echo '<Connector command="' . $command . '" resourceType="' . $resourceType . '">' ;
+
+	// Add the current folder node.
+	echo '<CurrentFolder path="' . ConvertToXmlAttribute( $currentFolder ) . '" url="' . ConvertToXmlAttribute( GetUrlFromPath( $resourceType, $currentFolder ) ) . '" />' ;
+}
+
+function CreateXmlFooter()
+{
+	echo '</Connector>' ;
+}
+
+function SendError( $number, $text )
+{
+	SetXmlHeaders() ;
+
+	// Create the XML document header
+	echo '<?xml version="1.0" encoding="utf-8" ?>' ;
+
+	echo '<Connector><Error number="' . $number . '" text="' . htmlspecialchars( $text ) . '" /></Connector>' ;
+
+	exit ;
+}
+?>
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/commands.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/commands.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/commands.php	(revision 290)
@@ -0,0 +1,221 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * This is the File Manager Connector for PHP.
+ */
+
+function GetFolders( $resourceType, $currentFolder )
+{
+	// Map the virtual path to the local server path.
+	$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
+
+	// Array that will hold the folders names.
+	$aFolders	= array() ;
+
+	$oCurrentFolder = opendir( $sServerDir ) ;
+
+	while ( $sFile = readdir( $oCurrentFolder ) )
+	{
+		if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) )
+			$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
+	}
+
+	closedir( $oCurrentFolder ) ;
+
+	// Open the "Folders" node.
+	echo "<Folders>" ;
+
+	natcasesort( $aFolders ) ;
+	foreach ( $aFolders as $sFolder )
+		echo $sFolder ;
+
+	// Close the "Folders" node.
+	echo "</Folders>" ;
+}
+
+function GetFoldersAndFiles( $resourceType, $currentFolder )
+{
+	// Map the virtual path to the local server path.
+	$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
+
+	// Arrays that will hold the folders and files names.
+	$aFolders	= array() ;
+	$aFiles		= array() ;
+
+	$oCurrentFolder = opendir( $sServerDir ) ;
+
+	while ( $sFile = readdir( $oCurrentFolder ) )
+	{
+		if ( $sFile != '.' && $sFile != '..' )
+		{
+			if ( is_dir( $sServerDir . $sFile ) )
+				$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
+			else
+			{
+				$iFileSize = filesize( $sServerDir . $sFile ) ;
+				if ( $iFileSize > 0 )
+				{
+					$iFileSize = round( $iFileSize / 1024 ) ;
+					if ( $iFileSize < 1 ) $iFileSize = 1 ;
+				}
+
+				$aFiles[] = '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
+			}
+		}
+	}
+
+	// Send the folders
+	natcasesort( $aFolders ) ;
+	echo '<Folders>' ;
+
+	foreach ( $aFolders as $sFolder )
+		echo $sFolder ;
+
+	echo '</Folders>' ;
+
+	// Send the files
+	natcasesort( $aFiles ) ;
+	echo '<Files>' ;
+
+	foreach ( $aFiles as $sFiles )
+		echo $sFiles ;
+
+	echo '</Files>' ;
+}
+
+function CreateFolder( $resourceType, $currentFolder )
+{
+	$sErrorNumber	= '0' ;
+	$sErrorMsg		= '' ;
+
+	if ( isset( $_GET['NewFolderName'] ) )
+	{
+		$sNewFolderName = $_GET['NewFolderName'] ;
+
+		if ( strpos( $sNewFolderName, '..' ) !== FALSE )
+			$sErrorNumber = '102' ;		// Invalid folder name.
+		else
+		{
+			// Map the virtual path to the local server path of the current folder.
+			$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
+
+			if ( is_writable( $sServerDir ) )
+			{
+				$sServerDir .= $sNewFolderName ;
+
+				$sErrorMsg = CreateServerFolder( $sServerDir ) ;
+
+				switch ( $sErrorMsg )
+				{
+					case '' :
+						$sErrorNumber = '0' ;
+						break ;
+					case 'Invalid argument' :
+					case 'No such file or directory' :
+						$sErrorNumber = '102' ;		// Path too long.
+						break ;
+					default :
+						$sErrorNumber = '110' ;
+						break ;
+				}
+			}
+			else
+				$sErrorNumber = '103' ;
+		}
+	}
+	else
+		$sErrorNumber = '102' ;
+
+	// Create the "Error" node.
+	echo '<Error number="' . $sErrorNumber . '" originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />' ;
+}
+
+function FileUpload( $resourceType, $currentFolder )
+{
+	$sErrorNumber = '0' ;
+	$sFileName = '' ;
+
+	if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
+	{
+		global $Config ;
+
+		$oFile = $_FILES['NewFile'] ;
+
+		// Map the virtual path to the local server path.
+		$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
+
+		// Get the uploaded file name.
+		$sFileName = $oFile['name'] ;
+
+		// Replace dots in the name with underscores (only one dot can be there... security issue).
+		if ( $Config['ForceSingleExtension'] )
+			$sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ;
+
+		$sOriginalFileName = $sFileName ;
+
+		// Get the extension.
+		$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
+		$sExtension = strtolower( $sExtension ) ;
+
+		// Check if it is an allowed extension.
+		if ( IsAllowedExt( $sExtension, $resourceType ) )
+		{
+			$iCounter = 0 ;
+
+			while ( true )
+			{
+				$sFilePath = $sServerDir . $sFileName ;
+
+				if ( is_file( $sFilePath ) )
+				{
+					$iCounter++ ;
+					$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
+					$sErrorNumber = '201' ;
+				}
+				else
+				{
+					move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
+
+					if ( is_file( $sFilePath ) )
+					{
+						$oldumask = umask(0) ;
+						chmod( $sFilePath, 0777 ) ;
+						umask( $oldumask ) ;
+					}
+
+					break ;
+				}
+			}
+		}
+		else
+			$sErrorNumber = '202' ;
+	}
+	else
+		$sErrorNumber = '202' ;
+
+
+	$sFileUrl = $Config["UserFilesPath"] . $resourceType . '/' . $sFileName ;
+
+	SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
+
+	exit ;
+}
+?>
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/config.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/config.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/config.php	(revision 290)
@@ -0,0 +1,75 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * Configuration file for the File Manager Connector for PHP.
+ */
+
+global $Config ;
+
+// SECURITY: You must explicitelly enable this "connector". (Set it to "true").
+$Config['Enabled'] = false ;
+
+// @Packager.Remove.Start
+// Attention: In the development version (SVN) the PHP connector is enabled by default.
+$Config['Enabled'] = true ;
+// @Packager.Remove.End
+
+// Path to user files relative to the document root.
+$Config['UserFilesPath'] = '/userfiles/' ;
+
+// Fill the following value it you prefer to specify the absolute path for the
+// user files directory. Usefull if you are using a virtual directory, symbolic
+// link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
+// Attention: The above 'UserFilesPath' must point to the same directory.
+//$Config['UserFilesAbsolutePath'] = '' ;
+// DISABLED:
+// You must set the corresponding paths in the FileTypesAbsolutePath configurations below.
+
+// Due to security issues with Apache modules, it is reccomended to leave the
+// following setting enabled.
+$Config['ForceSingleExtension'] = true ;
+
+// What the user can do with this connector
+$Config['ConfigAllowedCommands'] = array('FileUpload', 'GetFolders', 'GetFoldersAndFiles', 'CreateFolder') ;
+
+// Allowed and Denied extensions configurations.
+$Config['ConfigAllowedTypes'] = array('File', 'Image', 'Flash', 'Media') ;
+
+$Config['AllowedExtensions']['File']	= array() ;
+$Config['DeniedExtensions']['File']		= array('html','htm','php','php2','php3','php4','php5','phtml','pwml','inc','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','com','dll','vbs','js','reg','cgi','htaccess','asis') ;
+$Config['FileTypesPath']['File']		= $Config['UserFilesPath'] . 'file/' ;
+$Config['FileTypesAbsolutePath']['File']= '' ;
+
+$Config['AllowedExtensions']['Image']	= array('jpg','gif','jpeg','png') ;
+$Config['DeniedExtensions']['Image']	= array() ;
+$Config['FileTypesPath']['Image']		= $Config['UserFilesPath'] . 'image/' ;
+$Config['FileTypesAbsolutePath']['Image']= '' ;
+
+$Config['AllowedExtensions']['Flash']	= array('swf','fla') ;
+$Config['DeniedExtensions']['Flash']	= array() ;
+$Config['FileTypesPath']['Flash']		= $Config['UserFilesPath'] . 'flash/' ;
+$Config['FileTypesAbsolutePath']['Flash']= '' ;
+
+$Config['AllowedExtensions']['Media']	= array('swf','fla','jpg','gif','jpeg','png','avi','mpg','mpeg') ;
+$Config['DeniedExtensions']['Media']	= array() ;
+$Config['FileTypesPath']['Media']		= $Config['UserFilesPath'] . 'media/' ;
+$Config['FileTypesAbsolutePath']['Media']= '' ;
+?>
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/connector.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/connector.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/connector.php	(revision 290)
@@ -0,0 +1,83 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * This is the File Manager Connector for PHP.
+ */
+
+ob_start() ;
+
+require('config.php') ;
+require('util.php') ;
+require('io.php') ;
+require('basexml.php') ;
+require('commands.php') ;
+
+if ( !$Config['Enabled'] )
+	SendError( 1, 'This connector is disabled. Please check the "editor/filemanager/connectors/php/config.php" file' ) ;
+
+DoResponse() ;
+
+function DoResponse()
+{
+	if ( !isset( $_GET['Command'] ) || !isset( $_GET['Type'] ) || !isset( $_GET['CurrentFolder'] ) )
+		return ;
+
+	// Get the main request informaiton.
+	$sCommand		= $_GET['Command'] ;
+	$sResourceType	= $_GET['Type'] ;
+	$sCurrentFolder	= GetCurrentFolder() ;
+
+	// Check if it is an allowed command 
+	if ( ! IsAllowedCommand( $sCommand ) ) 
+		SendError( 1, 'The "' . $sCommand . '" command isn\'t allowed' ) ;
+
+	// Check if it is an allowed type.
+	if ( !IsAllowedType( $sResourceType ) )
+		SendError( 1, 'Invalid type specified' ) ;
+
+	// File Upload doesn't have to Return XML, so it must be intercepted before anything.
+	if ( $sCommand == 'FileUpload' )
+	{
+		FileUpload( $sResourceType, $sCurrentFolder ) ;
+		return ;
+	}
+
+	CreateXmlHeader( $sCommand, $sResourceType, $sCurrentFolder ) ;
+
+	// Execute the required command.
+	switch ( $sCommand )
+	{
+		case 'GetFolders' :
+			GetFolders( $sResourceType, $sCurrentFolder ) ;
+			break ;
+		case 'GetFoldersAndFiles' :
+			GetFoldersAndFiles( $sResourceType, $sCurrentFolder ) ;
+			break ;
+		case 'CreateFolder' :
+			CreateFolder( $sResourceType, $sCurrentFolder ) ;
+			break ;
+	}
+
+	CreateXmlFooter() ;
+
+	exit ;
+}
+?>
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/io.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/io.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/io.php	(revision 290)
@@ -0,0 +1,192 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * This is the File Manager Connector for PHP.
+ */
+function CombinePaths( $sBasePath, $sFolder )
+{
+	global $Config ;
+
+	return RemoveFromEnd( $sBasePath, '/' ) . '/' . RemoveFromStart( $sFolder, '/' ) ;
+}
+function GetResourceTypePath( $resourceType )
+{
+	global $Config ;
+
+	return $Config['FileTypesPath'][$resourceType] ;
+}
+
+function GetResourceTypeDirectory( $resourceType )
+{
+	global $Config ;
+	if ( strlen( $Config['FileTypesAbsolutePath'][$resourceType] ) > 0 )
+		return $Config['FileTypesAbsolutePath'][$resourceType] ;
+
+	// Map the "UserFiles" path to a local directory.
+	return GetRootPath() . $Config['FileTypesPath'][$resourceType] ;
+}
+
+function GetUrlFromPath( $resourceType, $folderPath )
+{
+	return CombinePaths( GetResourceTypePath( $resourceType ), $folderPath ) ;
+}
+
+function RemoveExtension( $fileName )
+{
+	return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
+}
+
+function ServerMapFolder( $resourceType, $folderPath )
+{
+	// Get the resource type directory.
+	$sResourceTypePath = GetResourceTypeDirectory( $resourceType ) ;
+
+	// Ensure that the directory exists.
+	CreateServerFolder( $sResourceTypePath ) ;
+
+	// Return the resource type directory combined with the required path.
+	return CombinePaths( $sResourceTypePath , $folderPath ) ;
+}
+
+function GetParentFolder( $folderPath )
+{
+	$sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ;
+	return preg_replace( $sPattern, '', $folderPath ) ;
+}
+
+function CreateServerFolder( $folderPath )
+{
+	$sParent = GetParentFolder( $folderPath ) ;
+
+	// Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms
+	while ( strpos($folderPath, '//') !== false )
+	{
+		$folderPath = str_replace( '//', '/', $folderPath ) ;
+	}
+
+	// Check if the parent exists, or create it.
+	if ( !file_exists( $sParent ) )
+	{
+		$sErrorMsg = CreateServerFolder( $sParent ) ;
+		if ( $sErrorMsg != '' )
+			return $sErrorMsg ;
+	}
+
+	if ( !file_exists( $folderPath ) )
+	{
+		// Turn off all error reporting.
+		error_reporting( 0 ) ;
+		// Enable error tracking to catch the error.
+		ini_set( 'track_errors', '1' ) ;
+
+		// To create the folder with 0777 permissions, we need to set umask to zero.
+		$oldumask = umask(0) ;
+		mkdir( $folderPath, 0777 ) ;
+		umask( $oldumask ) ;
+
+		$sErrorMsg = $php_errormsg ;
+
+		// Restore the configurations.
+		ini_restore( 'track_errors' ) ;
+		ini_restore( 'error_reporting' ) ;
+
+		return $sErrorMsg ;
+	}
+	else
+		return '' ;
+}
+
+function GetRootPath()
+{
+	$sRealPath = realpath( './' ) ;
+
+	$sSelfPath = $_SERVER['PHP_SELF'] ;
+	$sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
+
+	return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;
+}
+
+
+function IsAllowedExt( $extension, $resourceType )
+{
+	global $Config ;
+	// Get the allowed and denied extensions arrays.
+	$arAllowed	= $Config['AllowedExtensions'][$resourceType] ;
+	$arDenied	= $Config['DeniedExtensions'][$resourceType] ;
+
+	if ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) 
+		return false ;
+
+	if ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) 
+		return false ;
+
+	return true ;
+}
+
+function IsAllowedType( $resourceType )
+{
+	global $Config ;
+	if ( !in_array( $resourceType, $Config['ConfigAllowedTypes'] ) )
+		return false ;
+	
+	return true ;
+}
+
+function IsAllowedCommand( $sCommand )
+{
+	global $Config ;
+
+	if ( !in_array( $sCommand, $Config['ConfigAllowedCommands'] ) )
+		return false ;
+	
+	return true ;
+}
+
+function GetCurrentFolder()
+{
+	$sCurrentFolder	= isset( $_GET['CurrentFolder'] ) ? $_GET['CurrentFolder'] : '/' ;
+
+	// Check the current folder syntax (must begin and start with a slash).
+	if ( ! ereg( '/$', $sCurrentFolder ) ) $sCurrentFolder .= '/' ;
+	if ( strpos( $sCurrentFolder, '/' ) !== 0 ) $sCurrentFolder = '/' . $sCurrentFolder ;
+
+	// Ensure the folder path has no double-slashes
+	while ( strpos ($sCurrentFolder, '//') !== false ) {
+		$sCurrentFolder = str_replace ('//', '/', $sCurrentFolder) ;
+	}
+
+	// Check for invalid folder paths (..)
+	if ( strpos( $sCurrentFolder, '..' ) )
+		SendError( 102, '' ) ;
+
+	return $sCurrentFolder ;
+}
+
+// This is the function that sends the results of the uploading process.
+function SendUploadResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
+{
+	echo '<script type="text/javascript">' ;
+	echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
+	echo '</script>' ;
+	exit ;
+}
+
+?>
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/upload.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/upload.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/upload.php	(revision 290)
@@ -0,0 +1,52 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * This is the "File Uploader" for PHP.
+ */
+
+require('config.php') ;
+require('util.php') ;
+require('io.php') ;
+require('commands.php') ;
+
+// Check if this uploader has been enabled.
+if ( !$Config['Enabled'] )
+	SendUploadResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/connectors/php/config.php" file' ) ;
+
+$sCommand = 'FileUpload'
+
+// The file type (from the QueryString, by default 'File').
+$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;
+
+$sCurrentFolder	= GetCurrentFolder() ; 
+
+// Is enabled the upload?
+if ( ! IsAllowedCommand( $sCommand ) ) 
+	SendUploadResults( '1', '', '', 'The ""' . $sCommand . '"" command isn\'t allowed' ) ;
+
+// Check if it is an allowed type.
+if ( !IsAllowedType( $sType ) )
+    SendUploadResults( 1, '', '', 'Invalid type specified' ) ;
+
+
+FileUpload( $sType, $sCurrentFolder )
+
+?>
Index: /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/util.php
===================================================================
--- /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/util.php	(revision 290)
+++ /FCKeditor/branches/developers/alfonsoml/editor/filemanager/connectors/php/util.php	(revision 290)
@@ -0,0 +1,41 @@
+<?php
+/*
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * Utility functions for the File Manager Connector for PHP.
+ */
+
+function RemoveFromStart( $sourceString, $charToRemove )
+{
+	$sPattern = '|^' . $charToRemove . '+|' ;
+	return preg_replace( $sPattern, '', $sourceString ) ;
+}
+
+function RemoveFromEnd( $sourceString, $charToRemove )
+{
+	$sPattern = '|' . $charToRemove . '+$|' ;
+	return preg_replace( $sPattern, '', $sourceString ) ;
+}
+
+function ConvertToXmlAttribute( $value )
+{
+	return utf8_encode( htmlspecialchars( $value ) ) ;
+}
+?>
