3 * FCKeditor - The text editor for internet
4 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
6 * Licensed under the terms of the GNU Lesser General Public License:
7 * http://www.opensource.org/licenses/lgpl-license.php
9 * For further information visit:
10 * http://www.fckeditor.net/
12 * "Support Open Source software. What about a donation today?"
14 * File Name: connector.php
15 * This is the File Manager Connector for PHP.
18 * Frederico Caldeira Knabben (fredck@fckeditor.net)
26 include 'basexml.php';
27 include 'commands.php';
29 if ( !$Config['Enabled'] )
30 SendError( 1, 'This connector is disabled. Please check the "editor/filemanager/browser/default/connectors/php/config.php" file' ) ;
32 // Get the "UserFiles" path.
33 $GLOBALS["UserFilesPath"] = '' ;
35 if ( isset( $Config['UserFilesPath'] ) )
36 $GLOBALS["UserFilesPath"] = $Config['UserFilesPath'] ;
37 else if ( isset( $_GET['ServerPath'] ) )
38 $GLOBALS["UserFilesPath"] = $_GET['ServerPath'] ;
40 $GLOBALS["UserFilesPath"] = '/UserFiles/' ;
42 if ( ! preg_match( '/\/$/', $GLOBALS["UserFilesPath"] ) )
43 $GLOBALS["UserFilesPath"] .= '/' ;
45 if ( strlen( $Config['UserFilesAbsolutePath'] ) > 0 )
47 $GLOBALS["UserFilesDirectory"] = $Config['UserFilesAbsolutePath'] ;
49 if ( ! preg_match( '/\/$/', $GLOBALS["UserFilesDirectory"] ) )
50 $GLOBALS["UserFilesDirectory"] .= '/' ;
54 // Map the "UserFiles" path to a local directory.
55 $GLOBALS["UserFilesDirectory"] = GetRootPath() . $GLOBALS["UserFilesPath"] ;
62 if ( !isset( $_GET['Command'] ) || !isset( $_GET['Type'] ) || !isset( $_GET['CurrentFolder'] ) )
65 // Get the main request informaiton.
66 $sCommand = $_GET['Command'] ;
67 $sResourceType = $_GET['Type'] ;
68 $sCurrentFolder = $_GET['CurrentFolder'] ;
70 // Check if it is an allowed type.
71 if ( !in_array( $sResourceType, array('File','Image','Flash','Media') ) )
74 // Check the current folder syntax (must begin and start with a slash).
75 if ( ! preg_match( '/\/$/', $sCurrentFolder ) ) $sCurrentFolder .= '/' ;
76 if ( strpos( $sCurrentFolder, '/' ) !== 0 ) $sCurrentFolder = '/' . $sCurrentFolder ;
78 // Check for invalid folder paths (..)
79 if ( strpos( $sCurrentFolder, '..' ) )
80 SendError( 102, "" ) ;
82 // File Upload doesn't have to Return XML, so it must be intercepted before anything.
83 if ( $sCommand == 'FileUpload' )
85 FileUpload( $sResourceType, $sCurrentFolder ) ;
89 CreateXmlHeader( $sCommand, $sResourceType, $sCurrentFolder ) ;
91 // Execute the required command.
95 GetFolders( $sResourceType, $sCurrentFolder ) ;
97 case 'GetFoldersAndFiles' :
98 GetFoldersAndFiles( $sResourceType, $sCurrentFolder ) ;
100 case 'CreateFolder' :
101 CreateFolder( $sResourceType, $sCurrentFolder ) ;