1##### 2# FCKeditor - The text editor for Internet - http://www.fckeditor.net 3# Copyright (C) 2003-2007 Frederico Caldeira Knabben 4# 5# == BEGIN LICENSE == 6# 7# Licensed under the terms of any of the following licenses at your 8# choice: 9# 10# - GNU General Public License Version 2 or later (the "GPL") 11# http://www.gnu.org/licenses/gpl.html 12# 13# - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14# http://www.gnu.org/licenses/lgpl.html 15# 16# - Mozilla Public License Version 1.1 or later (the "MPL") 17# http://www.mozilla.org/MPL/MPL-1.1.html 18# 19# == END LICENSE == 20# 21# This is the File Manager Connector for Perl. 22##### 23 24sub GetUrlFromPath 25{ 26 local($resourceType, $folderPath) = @_; 27 28 if($resourceType eq '') { 29 $rmpath = &RemoveFromEnd($GLOBALS{'UserFilesPath'},'/'); 30 return("$rmpath$folderPath"); 31 } else { 32 return("$GLOBALS{'UserFilesPath'}$resourceType$folderPath"); 33 } 34} 35 36sub RemoveExtension 37{ 38 local($fileName) = @_; 39 local($path, $base, $ext); 40 if($fileName !~ /\./) { 41 $fileName .= '.'; 42 } 43 if($fileName =~ /([^\\\/]*)\.(.*)$/) { 44 $base = $1; 45 $ext = $2; 46 if($fileName =~ /(.*)$base\.$ext$/) { 47 $path = $1; 48 } 49 } 50 return($path,$base,$ext); 51 52} 53 54sub ServerMapFolder 55{ 56 local($resourceType,$folderPath) = @_; 57 58 # Get the resource type directory. 59 $sResourceTypePath = $GLOBALS{'UserFilesDirectory'} . $resourceType . '/'; 60 61 # Ensure that the directory exists. 62 &CreateServerFolder($sResourceTypePath); 63 64 # Return the resource type directory combined with the required path. 65 $rmpath = &RemoveFromStart($folderPath,'/'); 66 return("$sResourceTypePath$rmpath"); 67} 68 69sub GetParentFolder 70{ 71 local($folderPath) = @_; 72 73 $folderPath =~ s/[\/][^\/]+[\/]?$//g; 74 return $folderPath; 75} 76 77sub CreateServerFolder 78{ 79 local($folderPath) = @_; 80 81 $sParent = &GetParentFolder($folderPath); 82 # Check if the parent exists, or create it. 83 if(!(-e $sParent)) { 84 $sErrorMsg = &CreateServerFolder($sParent); 85 if($sErrorMsg == 1) { 86 return(1); 87 } 88 } 89 if(!(-e $folderPath)) { 90 umask(000); 91 mkdir("$folderPath",0777); 92 chmod(0777,"$folderPath"); 93 return(0); 94 } else { 95 return(1); 96 } 97} 98 99sub GetRootPath 100{ 101#use Cwd; 102 103# my $dir = getcwd; 104# print $dir; 105# $dir =~ s/$ENV{'DOCUMENT_ROOT'}//g; 106# print $dir; 107# return($dir); 108 109# $wk = $0; 110# $wk =~ s/\/connector\.cgi//g; 111# if($wk) { 112# $current_dir = $wk; 113# } else { 114# $current_dir = `pwd`; 115# } 116# return($current_dir); 117use Cwd; 118 119 if($ENV{'DOCUMENT_ROOT'}) { 120 $dir = $ENV{'DOCUMENT_ROOT'}; 121 } else { 122 my $dir = getcwd; 123 $workdir =~ s/\/connector\.cgi//g; 124 $dir =~ s/$workdir//g; 125 } 126 return($dir); 127 128 129 130} 1311; 132