Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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