Subversion Repositories Applications.papyrus

Rev

Rev 431 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 431 Rev 436
1
<?php 
1
<?php 
2
/*
2
/*
3
 * FCKeditor - The text editor for internet
3
 * FCKeditor - The text editor for internet
4
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
4
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
 * 
5
 * 
6
 * Licensed under the terms of the GNU Lesser General Public License:
6
 * Licensed under the terms of the GNU Lesser General Public License:
7
 * 		http://www.opensource.org/licenses/lgpl-license.php
7
 * 		http://www.opensource.org/licenses/lgpl-license.php
8
 * 
8
 * 
9
 * For further information visit:
9
 * For further information visit:
10
 * 		http://www.fckeditor.net/
10
 * 		http://www.fckeditor.net/
11
 * 
11
 * 
12
 * File Name: io.php
12
 * File Name: io.php
13
 * 	This is the File Manager Connector for ASP.
13
 * 	This is the File Manager Connector for ASP.
14
 * 
14
 * 
15
 * File Authors:
15
 * File Authors:
16
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
16
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
17
 */
17
 */
18
 
18
 
19
function GetUrlFromPath( $resourceType, $folderPath )
19
function GetUrlFromPath( $resourceType, $folderPath )
20
{
20
{
21
	if ( $resourceType == '' )
21
	if ( $resourceType == '' )
22
		return RemoveFromEnd( $GLOBALS["UserFilesPath"], '/' ) . $folderPath ;
22
		return RemoveFromEnd( $GLOBALS['UrlPrefix'].$GLOBALS["UserFilesPath"], '/' ) . $folderPath ;
23
	else
23
	else
24
		return $GLOBALS["UserFilesPath"] . $resourceType . $folderPath ;
24
		return $GLOBALS['UrlPrefix'].$GLOBALS["UserFilesPath"] . $resourceType . $folderPath ;
25
}
25
}
-
 
26
 
26
 
27
 
27
function RemoveExtension( $fileName )
28
function RemoveExtension( $fileName )
28
{
29
{
29
	return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
30
	return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
30
}
31
}
31
 
32
 
32
function ServerMapFolder( $resourceType, $folderPath )
33
function ServerMapFolder( $resourceType, $folderPath )
33
{
34
{
34
	// Get the resource type directory.
35
	// Get the resource type directory.
35
	$sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . '/' ;
36
	$sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . '/' ;
36
 
37
 
37
	// Ensure that the directory exists.
38
	// Ensure that the directory exists.
38
	CreateServerFolder( $sResourceTypePath ) ;
39
	CreateServerFolder( $sResourceTypePath ) ;
39
 
40
 
40
	// Return the resource type directory combined with the required path.
41
	// Return the resource type directory combined with the required path.
41
	return $sResourceTypePath . RemoveFromStart( $folderPath, '/' ) ;
42
	return $sResourceTypePath . RemoveFromStart( $folderPath, '/' ) ;
42
}
43
}
43
 
44
 
44
function GetParentFolder( $folderPath )
45
function GetParentFolder( $folderPath )
45
{
46
{
46
	$sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ;
47
	$sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ;
47
	return preg_replace( $sPattern, '', $folderPath ) ;
48
	return preg_replace( $sPattern, '', $folderPath ) ;
48
}
49
}
49
 
50
 
50
function CreateServerFolder( $folderPath )
51
function CreateServerFolder( $folderPath )
51
{
52
{
52
	$sParent = GetParentFolder( $folderPath ) ;
53
	$sParent = GetParentFolder( $folderPath ) ;
53
 
54
 
54
	// Check if the parent exists, or create it.
55
	// Check if the parent exists, or create it.
55
	if ( !file_exists( $sParent ) )
56
	if ( !file_exists( $sParent ) )
56
	{
57
	{
57
		$sErrorMsg = CreateServerFolder( $sParent ) ;
58
		$sErrorMsg = CreateServerFolder( $sParent ) ;
58
		if ( $sErrorMsg != '' )
59
		if ( $sErrorMsg != '' )
59
			return $sErrorMsg ;
60
			return $sErrorMsg ;
60
	}
61
	}
61
 
62
 
62
	if ( !file_exists( $folderPath ) )
63
	if ( !file_exists( $folderPath ) )
63
	{
64
	{
64
		// Turn off all error reporting.
65
		// Turn off all error reporting.
65
		error_reporting( 0 ) ;
66
		error_reporting( 0 ) ;
66
		// Enable error tracking to catch the error.
67
		// Enable error tracking to catch the error.
67
		ini_set( 'track_errors', '1' ) ;
68
		ini_set( 'track_errors', '1' ) ;
68
 
69
 
69
		// To create the folder with 0777 permissions, we need to set umask to zero.
70
		// To create the folder with 0777 permissions, we need to set umask to zero.
70
		$oldumask = umask(0) ;
71
		$oldumask = umask(0) ;
71
		mkdir( $folderPath, 0777 ) ;
72
		mkdir( $folderPath, 0777 ) ;
72
		umask( $oldumask ) ;
73
		umask( $oldumask ) ;
73
 
74
 
74
		$sErrorMsg = $php_errormsg ;
75
		$sErrorMsg = $php_errormsg ;
75
 
76
 
76
		// Restore the configurations.
77
		// Restore the configurations.
77
		ini_restore( 'track_errors' ) ;
78
		ini_restore( 'track_errors' ) ;
78
		ini_restore( 'error_reporting' ) ;
79
		ini_restore( 'error_reporting' ) ;
79
 
80
 
80
		return $sErrorMsg ;
81
		return $sErrorMsg ;
81
	}
82
	}
82
	else
83
	else
83
		return '' ;
84
		return '' ;
84
}
85
}
85
 
86
 
86
function GetRootPath()
87
function GetRootPath()
87
{
88
{
88
	$sRealPath = realpath( './' ) ;
89
	$sRealPath = realpath( './' ) ;
89
 
90
 
90
	$sSelfPath = $_SERVER['PHP_SELF'] ;
91
	$sSelfPath = $_SERVER['PHP_SELF'] ;
91
	$sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
92
	$sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
92
 
93
 
93
	return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;
94
	return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;
94
}
95
}
95
?>
96
?>