Subversion Repositories Applications.papyrus

Rev

Rev 431 | Go to most recent revision | Details | Compare with Previous | 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 == '' )
436 ddelon 22
		return RemoveFromEnd( $GLOBALS['UrlPrefix'].$GLOBALS["UserFilesPath"], '/' ) . $folderPath ;
431 ddelon 23
	else
436 ddelon 24
		return $GLOBALS['UrlPrefix'].$GLOBALS["UserFilesPath"] . $resourceType . $folderPath ;
431 ddelon 25
}
26
 
436 ddelon 27
 
431 ddelon 28
function RemoveExtension( $fileName )
29
{
30
	return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
31
}
32
 
33
function ServerMapFolder( $resourceType, $folderPath )
34
{
35
	// Get the resource type directory.
36
	$sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . '/' ;
37
 
38
	// Ensure that the directory exists.
39
	CreateServerFolder( $sResourceTypePath ) ;
40
 
41
	// Return the resource type directory combined with the required path.
42
	return $sResourceTypePath . RemoveFromStart( $folderPath, '/' ) ;
43
}
44
 
45
function GetParentFolder( $folderPath )
46
{
47
	$sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ;
48
	return preg_replace( $sPattern, '', $folderPath ) ;
49
}
50
 
51
function CreateServerFolder( $folderPath )
52
{
53
	$sParent = GetParentFolder( $folderPath ) ;
54
 
55
	// Check if the parent exists, or create it.
56
	if ( !file_exists( $sParent ) )
57
	{
58
		$sErrorMsg = CreateServerFolder( $sParent ) ;
59
		if ( $sErrorMsg != '' )
60
			return $sErrorMsg ;
61
	}
62
 
63
	if ( !file_exists( $folderPath ) )
64
	{
65
		// Turn off all error reporting.
66
		error_reporting( 0 ) ;
67
		// Enable error tracking to catch the error.
68
		ini_set( 'track_errors', '1' ) ;
69
 
70
		// To create the folder with 0777 permissions, we need to set umask to zero.
71
		$oldumask = umask(0) ;
72
		mkdir( $folderPath, 0777 ) ;
73
		umask( $oldumask ) ;
74
 
75
		$sErrorMsg = $php_errormsg ;
76
 
77
		// Restore the configurations.
78
		ini_restore( 'track_errors' ) ;
79
		ini_restore( 'error_reporting' ) ;
80
 
81
		return $sErrorMsg ;
82
	}
83
	else
84
		return '' ;
85
}
86
 
87
function GetRootPath()
88
{
89
	$sRealPath = realpath( './' ) ;
90
 
91
	$sSelfPath = $_SERVER['PHP_SELF'] ;
92
	$sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
93
 
94
	return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;
95
}
96
?>